* allow running with restricted permissions
This commit is contained in:
parent
bd64b0303b
commit
6874f44b86
|
@ -6,6 +6,8 @@ import java.util.concurrent.ScheduledFuture;
|
||||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||||
import java.util.concurrent.ThreadFactory;
|
import java.util.concurrent.ThreadFactory;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
|
||||||
public abstract class Timer implements Runnable {
|
public abstract class Timer implements Runnable {
|
||||||
|
@ -31,7 +33,12 @@ public abstract class Timer implements Runnable {
|
||||||
Runnable runnable = this;
|
Runnable runnable = this;
|
||||||
|
|
||||||
if (runBeforeShutdown) {
|
if (runBeforeShutdown) {
|
||||||
addShutdownHook();
|
try {
|
||||||
|
addShutdownHook();
|
||||||
|
} catch (Exception e) {
|
||||||
|
// may fail if running with restricted permissions
|
||||||
|
Logger.getLogger(getClass().getName()).log(Level.WARNING, e.getClass().getName() + ": " + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
// remove shutdown hook after execution
|
// remove shutdown hook after execution
|
||||||
runnable = new Runnable() {
|
runnable = new Runnable() {
|
||||||
|
@ -46,8 +53,13 @@ public abstract class Timer implements Runnable {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
// remove existing shutdown hook, if any
|
try {
|
||||||
removeShutdownHook();
|
// remove existing shutdown hook, if any
|
||||||
|
removeShutdownHook();
|
||||||
|
} catch (Exception e) {
|
||||||
|
// may fail if running with restricted permissions
|
||||||
|
Logger.getLogger(getClass().getName()).log(Level.WARNING, e.getClass().getName() + ": " + e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
scheduledFuture = executor.schedule(runnable, delay, unit);
|
scheduledFuture = executor.schedule(runnable, delay, unit);
|
||||||
|
|
Loading…
Reference in New Issue