Search code examples
javathreadpooldaemonshutdown

Do ThreadPoolExecutors that create daemon threads require shutdown?


This seemed to happen in my application but was almost certainly the result of something else going on in my Maven / JUnit test case environment (on code I haven't even fully read - maintaining a foreign project). The following code works as desired, and the TPE doesn't require shutdown:

final ScheduledThreadPoolExecutor pool = new ScheduledThreadPoolExecutor(1, new ThreadFactory() {

        @Override
        public Thread newThread(Runnable task) {

            Thread thread = new Thread(task, replenisherThreadName);
            thread.setDaemon(true);
            return thread;
        }
    });

Solution

  • if it is truly a daemon thread, then it is not keeping your application alive. your problem lies elsewhere (or it's not really a daemon thread).