In python I can set a thread to be a daemon, meaning if parent dies, the child thread automatically dies along with it.
Is there an equivalent in Java?
Currently I am starting a thread like this in Java, but the underlying child thread does not die and hang even if main thread exits
executor = Executors.newSingleThreadExecutor();
executor.submit(() -> {
while (true) {
//Stopwatch stopwatch = Stopwatch.createStarted();
String threadName = Thread.currentThread().getName();
System.out.println("Hello " + threadName);
try {
Thread.sleep(1*1000);
} catch (InterruptedException e) {
break;
}
}
});
Threadin Java so such a thing could not be implemented.