Tuesday, October 12, 2010

Timer Daemon thread


public Timer(boolean isDaemon)

Creates a new timer whose associated thread may be specified to run as a daemon (background).A daemon thread exit automatically when JVM exits. If it is not a daemon (foreground), timer.cancel() need to called explicitly to make the thread exit.

When a JVM shutdown hook is registered, it waits for all non-daemon threads exit with thread.join(). I run into this issue when there is a non-daemon timer thread and block the JVM from exiting.

No comments: