Example of a cached-thread-pool where all threads are daemon-threads
This file contains 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.util.concurrent.ExecutorService; | |
import java.util.concurrent.Executors; | |
import java.util.concurrent.ThreadFactory; | |
public class ImprovedCachedThreads { | |
public static void main(String[] args) { | |
final ThreadFactory threadFactory = runnable -> { | |
final Thread thread = new Thread(runnable, "HelloWorldThread"); | |
thread.setDaemon(true); | |
return thread; | |
}; | |
final ExecutorService executor = Executors.newCachedThreadPool(threadFactory); | |
executor.submit(() -> System.out.println("Hello World")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment