Timer thread termination may not be detected and cause non-clean VM shutdown
Alan.Bateman at oracle.com
Tue Sep 13 02:33:37 PDT 2011
Jing LV wrote:
> 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.
I don't understand the comment about the problem when using the attach
API. Are you see problems on the tool side or target VM side? Just
curious as the attach API doesn't use Timer. When it does a thread dump
then there will be timer threads but that's all.
In any case I think we should encourage developers to move to
More information about the core-libs-dev