The javadoc of Executors.newFixedThreadPool()
states
The threads in the pool will exist until it is explicitly
shutdown
.
Basically that ExecutorService
spawns some non-daemon threads that it doesn't stop until you call shutdown()
. Your process will not end until all non-daemon threads die.
So call it if you need your application to end or use your own ThreadFactory. Here is an improved version using daemon threads and a thread pool with as many threads as your computer has CPU cores:
Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors(), new ThreadFactory()
{
@Override
public Thread newThread(final Runnable r) {
Thread t = new Thread(r);
t.setDaemon(true);
return t;
}
});