Reputation: 1564
When I read the source code of java.util.Timer
, I found that java.util.Timer
is implemented by a TimerThread
and a TaskQueue
It is said that java.util.Timer
can be cancelled by java.util.Timer.cancel()
,
But when I call java.util.Timer.cancel()
I found TimerThread in Timer still running ,
Does this a problem for online system ?
And if possible , how can I stop TimerThread
inside java.util.Timer
?
From source of TimerThread
(jdk 7) I finally found that Timer.cancel()
do works.
TimerThread wait TaskQueue
, when Timer.cancel()
called , TaskQueue
notify TimerThread
, And TimerThead should finally exit if `TaskQueue is EMPTY...
Thank you for your comment , sorry to wasting your time.
Upvotes: 1
Views: 4300
Reputation: 5496
Timer
is single thread which holds list of Task
to execute, once all Task are executed suucessfully the Timer
thread instance will called by Garbage Collector
after some time
Upvotes: 1
Reputation: 2883
Timer thread will still be running. But the timer thread will stop accepting anything into the queue as per the implementation.
The timer
(TimerThread) thread is accessible to you only via Timer
class. TimerThread
is encapsultaed inside Timer
class. Implementation wise, they have made sure the Timer stops accepting the requests to its queue, but the TimerThread
as such is not stopped.
Upvotes: 2
Reputation: 680
This might help you...The section describes the reasons in some cases the timer thread doesn't end.
http://enos.itcollege.ee/~jpoial/docs/tutorial/essential/threads/timer.html
Upvotes: 0