I am using an ExecutoreService in Java 1.6, started simply by
ExecutorService pool = Executors.newFixedThreadPool(THREADS).
When my main
You can use Guava's ThreadFactoryBuilder. I didn't want to add the dependency and I wanted the functionality from Executors.DefaultThreadFactory, so I used composition:
class DaemonThreadFactory implements ThreadFactory {
final ThreadFactory delegate;
DaemonThreadFactory() {
this(Executors.defaultThreadFactory());
}
DaemonThreadFactory(ThreadFactory delegate) {
this.delegate = delegate;
}
@Override
public Thread newThread(Runnable r) {
Thread thread = delegate.newThread(r);
thread.setDaemon(true);
return thread;
}
}