This commit is contained in:
Armin Schrenk
2022-08-31 13:35:27 +02:00
parent 40fa961b9b
commit b4f95c465a
2 changed files with 19 additions and 1 deletions

View File

@@ -10,6 +10,7 @@ import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
@@ -28,6 +29,18 @@ public final class CatchingExecutors {
super(corePoolSize, threadFactory);
}
@Override
public ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit) {
Runnable oneShot = () -> this.execute(command);
return super.scheduleAtFixedRate(oneShot, initialDelay, period, unit);
}
@Override
public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit) {
Runnable oneShot = () -> this.execute(command);
return super.scheduleWithFixedDelay(oneShot, initialDelay, delay, unit);
}
@Override
protected void afterExecute(Runnable runnable, Throwable throwable) {
super.afterExecute(runnable, throwable);
@@ -77,6 +90,12 @@ public final class CatchingExecutors {
}
private static void afterExecuteFuture(Future<?> future) {
if (future instanceof ScheduledFuture<?> && !future.isDone()) {
//we assume that this must be a repeated ScheduledFutureTask, where the done-status is only set when not executed anymore
//see also https://github.com/cryptomator/cryptomator/pull/2422
return;
}
try {
future.get();
} catch (CancellationException ce) {

View File

@@ -46,7 +46,6 @@ public class AutoLocker {
private boolean exceedsIdleTime(Vault vault) {
assert vault.isUnlocked();
// TODO: shouldn't we read these properties from within FX Application Thread?
if (vault.getVaultSettings().autoLockWhenIdle().get()) {
int maxIdleSeconds = vault.getVaultSettings().autoLockIdleSeconds().get();
var deadline = vault.getStats().getLastActivity().plusSeconds(maxIdleSeconds);