Return-Path: X-Original-To: apmail-tomcat-users-archive@www.apache.org Delivered-To: apmail-tomcat-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 42A9C6C4E for ; Tue, 12 Jul 2011 18:19:21 +0000 (UTC) Received: (qmail 16644 invoked by uid 500); 12 Jul 2011 18:19:17 -0000 Delivered-To: apmail-tomcat-users-archive@tomcat.apache.org Received: (qmail 16467 invoked by uid 500); 12 Jul 2011 18:19:16 -0000 Mailing-List: contact users-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Users List" Delivered-To: mailing list users@tomcat.apache.org Received: (qmail 16458 invoked by uid 99); 12 Jul 2011 18:19:16 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 12 Jul 2011 18:19:16 +0000 X-ASF-Spam-Status: No, hits=1.0 required=5.0 tests=SPF_SOFTFAIL X-Spam-Check-By: apache.org Received-SPF: softfail (nike.apache.org: transitioning domain of terence@tmbsw.com does not designate 207.44.152.30 as permitted sender) Received: from [207.44.152.30] (HELO secure.savvysites.net) (207.44.152.30) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 12 Jul 2011 18:19:07 +0000 Received: from [192.168.1.3] (208-191-156-72.lightspeed.austtx.sbcglobal.net [208.191.156.72]) (authenticated bits=0) by secure.savvysites.net (8.12.10/8.12.10) with ESMTP id p6CIINOj020603 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 12 Jul 2011 13:18:24 -0500 Message-ID: <4E1C907B.50904@tmbsw.com> Date: Tue, 12 Jul 2011 13:20:43 -0500 From: "Terence M. Bandoian" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.4) Gecko/20100608 Lightning/1.0b2 Thunderbird/3.1 MIME-Version: 1.0 To: Tomcat Users List Subject: Terminating Timer Thread Gracefully References: <4E1C01A2.9090702@pidster.com> In-Reply-To: <4E1C01A2.9090702@pidster.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org Thanks to all who replied. Functionally, the servlet context listener is implemented as follows: public class AServletContextListener implements ServletContextListener { private Timer timer; private ATimerTask timerTask; public AServletContextListener() { } public void contextInitialized( ServletContextEvent sce ) { if ( timer == null ) { Calendar firstRunTime; timer = new Timer( true ); timerTask = new ATimerTask(); firstRunTime = new GregorianCalendar(); firstRunTime.set( Calendar.HOUR_OF_DAY, 12 ); firstRunTime.set( Calendar.MINUTE, 0 ); firstRunTime.set( Calendar.SECOND, 0 ); firstRunTime.set( Calendar.MILLISECOND, 0 ); timer.scheduleAtFixedRate( timerTask, firstRunTime.getTime(), 1000 * 60 * 60 * 24 ); } } public void contextDestroyed( ServletContextEvent sce ) { if ( timer != null ) { timer.cancel(); timer.purge(); timer = null; timerTask = null; try { Thread.sleep( 1000 ); } catch ( InterruptedException ie ) { } } } } If I remove the call to Thread.sleep, the error message is written to the logs. Timer tasks are scheduled no more often than daily and none are executing when the context is destroyed. The one second delay appears to work reliably. I haven't yet tested with other values. The real question may be, as Len suggested, what does "terminates gracefully" mean in relation to the execution thread of a canceled Timer? Thanks again. -Terence Bandoian On 1:59 PM, Pid wrote: > On 12/07/2011 02:06, Terence M. Bandoian wrote: >> Hi- >> >> I've been testing a web application on: >> >> Tomcat 6.0.32 (32-bit) >> Sun/Oracle JRE 1.6.0_25 (32-bit) >> Windows Server 2008 R2 >> >> The web application includes a ServletContextListener which creates a >> Timer in the contextInitialized method to perform periodic maintenance. >> To no avail, I spent quite a bit of time trying to eliminate the "The >> web application appears to have started a thread..." error message from >> the logs including logging the cancellation of the timer in the >> contextDestroyed method of the ServletContextListener. Finally, in >> contextDestroyed, I inserted a call to Thread.sleep after canceling the >> timer and the error message disappeared. >> >> Is there some other way to eliminate this message that I've missed? > Hard to know, can you post the code you used to start/stop the timer? > > > p > > >> -Terence Bandoian >> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org >> For additional commands, e-mail: users-help@tomcat.apache.org >> > --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org For additional commands, e-mail: users-help@tomcat.apache.org