On Tue, Jul 12, 2011 at 10:03 AM, David kerber <dcker...@verizon.net> wrote:
> On 7/12/2011 9:59 AM, Kris Schneider wrote:
>>
>> On Tue, Jul 12, 2011 at 7:59 AM, Caldarale, Charles R
>> <chuck.caldar...@unisys.com>  wrote:
>>>>
>>>> From: Terence M. Bandoian [mailto:tere...@tmbsw.com]
>>>> Subject: Terminating Timer Thread Gracefully
>>>
>>>> Finally, in contextDestroyed, I inserted a call to
>>>> Thread.sleep after canceling the timer and the error
>>>> message disappeared.
>>>
>>> You should be able to do a Thread.join() using the timer's Thread object
>>> rather than sleeping.
>>
>> But Timer doesn't expose its thread. An alternative would be use
>> something like Executors.newSingleThreadScheduledExecutor() to get a
>> ScheduledExecutorService. The executor can be used to schedule a
>> Runnable with a fixed rate or delay. When the context is destroyed,
>> shutdown the executor and await its termination.
>
> No need even to do that; just .cancel() the timer.

Maybe. It sounds like that's been working for you, but I thought the
OP had already tried that. A potential issue with Timer.cancel() is
that there really aren't any guarantees about when the associated
thread is terminated and there certainly isn't any way for external
code to interact with it. Using something like an ExecutorService just
seems like a better approach to this sort of thing.

-- 
Kris Schneider

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to