R
Richard
Hello,
It was always my understanding that if you did not want a thread to
keep a program open then is should be a daemon thread. In other words
it is a background thread. I was doing some work with the
ScheduledExecutorService (http://java.sun.com/j2se/1.5.0/docs/api/java/
util/concurrent/ScheduledExecutorService.html) last week and I
suddenly realised that the thread was keeping my program open
occasionally. Digging a little and I discovered the thread that this
produces are not daemon. This goes against my understanding. The fact
that it is scheduled implies to me that it is doing a background task.
For this thread you must explicitly call shutdown on the executor in
order for it to die.
I have made my ScheduledExecutorService daemon by passing in my own
ThreadFactory and making sure that all the threads this produce are
daemon.
Is my understanding of what a daemon thread is correct? Is it odd to
anyone else that the ScheduledExecutorService produces non-daemon
thread?
Thanks
Richard
It was always my understanding that if you did not want a thread to
keep a program open then is should be a daemon thread. In other words
it is a background thread. I was doing some work with the
ScheduledExecutorService (http://java.sun.com/j2se/1.5.0/docs/api/java/
util/concurrent/ScheduledExecutorService.html) last week and I
suddenly realised that the thread was keeping my program open
occasionally. Digging a little and I discovered the thread that this
produces are not daemon. This goes against my understanding. The fact
that it is scheduled implies to me that it is doing a background task.
For this thread you must explicitly call shutdown on the executor in
order for it to die.
I have made my ScheduledExecutorService daemon by passing in my own
ThreadFactory and making sure that all the threads this produce are
daemon.
Is my understanding of what a daemon thread is correct? Is it odd to
anyone else that the ScheduledExecutorService produces non-daemon
thread?
Thanks
Richard