1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-12-24 16:58:51 -05:00

* allow running with restricted permissions

This commit is contained in:
Reinhard Pointner 2011-12-31 10:45:22 +00:00
parent bd64b0303b
commit 6874f44b86

View File

@ -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) {
try {
addShutdownHook(); 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 {
try {
// remove existing shutdown hook, if any // remove existing shutdown hook, if any
removeShutdownHook(); 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);