Timer thread termination may not be detected and cause non-clean VM shutdown
lvjing at linux.vnet.ibm.com
Tue Sep 13 07:51:29 UTC 2011
I've meet a subtle issue with Timer. As we know, every Timer objects
spawn a new thread (which is optionally a daemon thread). On VM
shutdown, there is no way to ensure that the daemon thread terminates
(cancel() and purge() only clear the queue). This can lead to non-clean
VM shutdown (return non-zero exit code) and has caused problems in some
applications especailly with attach API. Further, there is no way to
determine when all tasks have completed after calling cancel().
This problem was encouraged to occur when the test machine was busy. The
original failure occurs when created & destroyed 15 processes with 1
JVM's each (via JNI). It seems all versions of JDK has this issue.
I was trying to make a simple testcase but no much progress - though
logically I guess everyone can understand this easily. Current my
workaround is to have some thread to join the Timer thread to wait its
termination - but it seems have some side effect and cause problems.
A quick idea to resolve the problem completely is to add a new API like
"public void cancel(boolean wait)" to indicate if we will wait for the
Timer threads to be terminated, or add some private methods to help the
VM to do something to terminate the Timer.
Any suggestions/comments? Thanks.
Jimmy, Jing LV
More information about the core-libs-dev