This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<dependency> | |
<groupId>org.gridkit.lab</groupId> | |
<artifactId>nanocloud</artifactId> | |
<version>0.8.8</version> | |
</dependency> | |
<dependency> | |
<groupId>org.gridkit.lab</groupId> | |
<artifactId>telecontrol-ssh</artifactId> | |
<version>0.8.8</version> | |
</dependency> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.lang.ref.WeakReference; | |
import java.util.concurrent.*; | |
import java.util.function.Consumer; | |
public class SchedulerLeakProtector { | |
public static <T> ScheduledFuture<?> scheduleAtFixedRate(ScheduledExecutorService scheduler, T target, Consumer<T> consumer, long initialDelay, long period, TimeUnit timeUnit) { | |
CompletableFuture<ScheduledFuture<?>> scheduledFutureFuture = new CompletableFuture<>(); | |
LeakProtectedRunnable<T> runnable = new LeakProtectedRunnable<>(target, consumer, scheduledFutureFuture); | |
ScheduledFuture<?> scheduledFuture = scheduler.scheduleAtFixedRate(runnable, initialDelay, period, timeUnit); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Executor which useful for unit testing | |
*/ | |
public class CurrentThreadExecutor implements ExecutorService { | |
@Override | |
public void execute(Runnable command) { | |
command.run(); | |
} |
NewerOlder