tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Pid <...@pidster.com>
Subject Re: Terminating Timer Thread Gracefully
Date Wed, 13 Jul 2011 15:48:58 GMT
On 12/07/2011 20:47, Terence M. Bandoian wrote:
>  Hi, Kris-
> 
> I tried using ScheduledExecutorService but ran into the same problem. 
> After awaiting termination:
> 
>             executorService.shutdown();
> 
>             try
>             {
>                 while ( !executorService.awaitTermination(
>                     1, TimeUnit.SECONDS ) );
> 
>                 Thread.sleep( 1000 );
>             }
>             catch ( InterruptedException ie )
>             {
>             }
> 
> I still had to insert a call to Thread.sleep to prevent the error
> message from being written to the logs.

ATimerTask is a private instance in AServletContextListener, is this
necessary and if so, why?

What logic is contained in ATimerTask?

Are you overriding TimerTask.cancel() and do you catch InterruptedException?


p

> 
> Thanks.
> 
> -Terence Bandoian
> 
> On 1:59 PM, Kris Schneider wrote:
>> On Tue, Jul 12, 2011 at 7:59 AM, Caldarale, Charles R
>> <Chuck.Caldarale@unisys.com>  wrote:
>>>> From: Terence M. Bandoian [mailto:terence@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.
>>
>>>   - Chuck
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 



Mime
View raw message