I\'m having a problem with closing my application because some threads are still running after I close the application. Somebody can help me with some method to stop all Th
Executors from the java.util.concurrent
package are the way to go. Explicitly:
ExecutorService executorService = Executors.newCachedThreadPool(new ThreadFactory() {
@Override
public Thread newThread(Runnable runnable) {
Thread thread = Executors.defaultThreadFactory().newThread(runnable);
thread.setDaemon(true);
return thread;
}
});
ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1, r -> {
Thread thread = Executors.defaultThreadFactory().newThread(r);
thread.setDaemon(true);
return thread;
});