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 CFC1818EFD for ; Mon, 14 Dec 2015 13:24:50 +0000 (UTC) Received: (qmail 41624 invoked by uid 500); 14 Dec 2015 13:24:46 -0000 Delivered-To: apmail-tomcat-users-archive@tomcat.apache.org Received: (qmail 41549 invoked by uid 500); 14 Dec 2015 13:24:46 -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 41536 invoked by uid 99); 14 Dec 2015 13:24:46 -0000 Received: from Unknown (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 14 Dec 2015 13:24:46 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id 28B11C0EEB for ; Mon, 14 Dec 2015 13:24:46 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -0.011 X-Spam-Level: X-Spam-Status: No, score=-0.011 tagged_above=-999 required=6.31 tests=[SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01] autolearn=disabled Received: from mx1-eu-west.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id kHdivM1gi9gv for ; Mon, 14 Dec 2015 13:24:45 +0000 (UTC) Received: from vms173025pub.verizon.net (vms173025pub.verizon.net [206.46.173.25]) by mx1-eu-west.apache.org (ASF Mail Server at mx1-eu-west.apache.org) with ESMTPS id CD31820EBA for ; Mon, 14 Dec 2015 13:24:44 +0000 (UTC) Received: from [172.17.47.42] ([65.199.184.146]) by vms173025.mailsrvcs.net (Oracle Communications Messaging Server 7.0.5.32.0 64bit (built Jul 16 2014)) with ESMTPA id <0NZC0045KNWQI670@vms173025.mailsrvcs.net> for users@tomcat.apache.org; Mon, 14 Dec 2015 07:24:37 -0600 (CST) X-CMAE-Score: 0 X-CMAE-Analysis: v=2.1 cv=WcjxEBVX c=1 sm=1 tr=0 a=ghRDmrgUihQ+t5fp33utJQ==:117 a=o1OHuDzbAAAA:8 a=oR5dmqMzAAAA:8 a=N659UExz7-8A:10 a=wUQvQvOEmiQA:10 a=JMzO2ykTMU0lYRf5uDEA:9 a=pILNOxqGKmIA:10 Subject: Re: Context destroy sequence of events To: users@tomcat.apache.org References: <566AD002.3070507@verizon.net> <566AFCB0.7020903@verizon.net> <566B41CC.6070202@apache.org> From: David kerber Message-id: <566EC30A.3090201@verizon.net> Date: Mon, 14 Dec 2015 08:24:26 -0500 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.4.0 MIME-version: 1.0 In-reply-to: <566B41CC.6070202@apache.org> Content-type: text/plain; charset=windows-1252; format=flowed Content-transfer-encoding: 7bit On 12/11/2015 4:36 PM, Mark Thomas wrote: > On 11/12/2015 16:41, David kerber wrote: >> On 12/11/2015 8:30 AM, David kerber wrote: >>> Running TC 8.0.22 with JRE 1.8.0.60 on Windows 2008 R2, as a windows >>> service. >>> >>> Can someone point me to a reference that will tell me exactly what the >>> sequence of events is when a servlet that is running as a windows >>> service, is shut down? >>> >>> My situation is that my application receives data in a continuous stream >>> and caches them for a period of time. Then based on a couple of >>> different triggers, it will write them to disk. >>> >>> What I need is a way to allow the windows service to be stopped in such >>> a way that the servlet will not accept any more data while I flush my >>> caches to disk. This ensures that I don't lose any data during the >>> shutdown (the remote clients that are sending the data will not move on >>> to the next piece of data until they get the correct response from the >>> server for the previous one). >>> >>> If I can ensure that (for example) the servlet will not accept any more >>> connections when contextDestroyed event is triggered, but I will still >>> be able to call my cache flushing routines, I think that would do what I >>> need. >>> >>> Or if I can use the contextDestroyed event to set a flag in my >>> servlet.doPost method to tell it to stop processing, that would work >>> too. Then I can call my cache flushing after that. >>> >>> Suggestions? >> >> Is Servlet.destroy() the place for this kind of cleanup? > > Definitely not. In theory, a Servlet container can take any Servlet out > of service any time it likes (as long as it is not is use) e.g. to > reduce memory pressure. > > In a standard container stop the following happens (in this order, not > exhaustive) > - The connectors are paused so no new requests are processed > - Existing requests continue to process > - The Engine, Host and Contexts are stopped > - The Contexts wait a configurable period of time for any running > requests to finish (10s from memory although that might have changed) > - contextDestroyed() is called > > So, the short version is call your flushing code from contextDestroyed() > and you should be fine as long as you requests have finished. If they > haven't, increase the wait time. Thanks, Mark. My requests only take a fraction of a second to process, so I should be good with the default wait time. --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org For additional commands, e-mail: users-help@tomcat.apache.org