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 E8EE57271 for ; Tue, 20 Sep 2011 18:55:08 +0000 (UTC) Received: (qmail 25764 invoked by uid 500); 20 Sep 2011 18:55:05 -0000 Delivered-To: apmail-tomcat-users-archive@tomcat.apache.org Received: (qmail 25717 invoked by uid 500); 20 Sep 2011 18:55:05 -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 25708 invoked by uid 99); 20 Sep 2011 18:55:05 -0000 Received: from minotaur.apache.org (HELO minotaur.apache.org) (140.211.11.9) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 20 Sep 2011 18:55:05 +0000 Received: from localhost (HELO [192.168.23.9]) (127.0.0.1) (smtp-auth username markt, mechanism plain) by minotaur.apache.org (qpsmtpd/0.29) with ESMTP; Tue, 20 Sep 2011 18:55:04 +0000 Message-ID: <4E78E186.7000005@apache.org> Date: Tue, 20 Sep 2011 19:55:02 +0100 From: Mark Thomas User-Agent: Mozilla/5.0 (Windows NT 5.2; WOW64; rv:6.0.2) Gecko/20110902 Thunderbird/6.0.2 MIME-Version: 1.0 To: Tomcat Users List Subject: Re: Executor thread lifecycle References: In-Reply-To: X-Enigmail-Version: 1.3.2 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit On 20/09/2011 19:29, Dan Checkoway wrote: > I'm curious how long Executor threads live prior to being > recycled/replaced/what have you. Is there a way to control this lifecycle? No. > I'm using ThreadLocal to allocate some resources per thread... That is asking for a memory leak. There is a simple rule for correctly using a ThreadLocal in a web application. The ThreadLocal must be removed from the thread before the request/response in which it was created completes processing. > and the > behavior I'm seeing is that after some period of time, my ThreadLocal > goes away and needs to be reinitialized. It's implying to me that the > thread itself has been recycled. More recent versions of Tomcat will re-cycle threads and/or remove ThreadLocals detected when an application is reloaded as part of the memory leak prevention code. > What's making this more confusing is that the thread IDs appear to be > getting reused, so logging the thread ID isn't helping (it's probably > confusing me more than anything). > > Anyway, can somebody confirm if Tomcat has explicit deliberate control over > the Executor thread lifecycle, and if so, how I might be able to control > it? And if not, is there a way to control it? ThreadLocals are likely to be the wrong solution to the problem. If you need a resource across multiple, unrelated requests, the ServletContext is probably the way to go. Mark --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org For additional commands, e-mail: users-help@tomcat.apache.org