Reputation: 60828
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;
}
});
Upvotes: 1
Views: 548
Reputation: 551
Not sure about these daemon threads getting created via your program but ideally we should try to shutdown executor service, after completing our work. The reason being, I have observed it in many applications that when these services are not shutdown properly; thread count keep on piling up and this makes application unstable.
Upvotes: 0
Reputation: 53694
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).
Upvotes: 1