Say I have this:
private static ExecutorService executor = Executors.newFixedThreadPool(1);
executor.execute(() -> {
Thread.sleep(100);
doSomething();
});
since I am reusing a thread, I am blocking it if others want to use the thread. My question is - is there a way to simply register a callback, something like this:
executor.execute(() -> {
timers.setTimeout(() -> { // imaginary utility
doSomething();
},100);
});
is this possible with core Java?
CompletableFuturesThread.sleep()? The call toexecute()returns immediately, so your main thread will continue to be responsive