tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chip McVey <>
Subject RE: Permanent servlet in TC7
Date Thu, 26 Jul 2012 19:54:34 GMT
Hi Chris,

Thanks for the response.  Sorry, where I said "...unload a server any time" I should have
said 'servlet'.

I have read that Tomcat does not unload servlets (even though it would be permissible to do
so), but as you say, I have done some logging in the destroy method, and I see this behavior.

Here's the scenario:  I have 3 webapps, let's call them A, B, C.  They are all hosted in the
same TC7 instance currently, but they could also all be hosted on different machines in different
TC7 containers.

A certain servlet within app B & C (let's call them B1 and C1) upon init make a call to
a servlet in app A (let's call it A1). What I see is A1, B1, and C1 all initialize. The init
is done by a thread called " pool-2-thread-1", which seems like a system thread.  Ok no problem.

Then, for some reason, A1's destroy method is called, and it is called by a thread named "
http-apr-8080-exec-3", making me think it is being called by a thread processing the request
for either B1 or C1, since no other requests from anyone outside of B or C have happened yet.

After destroy winds down, then, A1's init method is called by a thread named " http-apr-8080-exec-11"
- another request processing thread I assume.   Everything all works out in the end, and after
that I don't see A1, B1, or C1 ever destroyed - but am I guaranteed that they won't ever be
destroyed again unless TC is shutdown or they are manually unloaded?

I understand that given servlets can by spec go up & down, maybe using them was not the
right choice for an application that needs permanency, but we're too late in development to
make that switch now.

So I'm looking for a guarantee that no automatic destroys will happen going forward just because
Tomcat decides to do it on its own.  If it is instructed to shutdown/undeploy/unload by some
outside system or by a human user, that's fine, I'm not worried about that.  But I don't want
these servlets to be destroyed just because Tomcat decides to do so for whatever reason.

Hope that helps clarify, and thanks for the feedback.

-----Original Message-----
From: Christopher Schultz [] 
Sent: Thursday, July 26, 2012 12:38 PM
To: Tomcat Users List
Subject: Re: Permanent servlet in TC7

Hash: SHA1


On 7/26/12 3:19 PM, Chip McVey wrote:
> In TC7, is there a way to tell Tomcat to never unload a given servlet 
> unless Tomcat itself is being shutdown?  I want a single servlet 
> instance that I can know will exist for the life of the tomcat process 
> without being unloaded & reloaded (unless someone manually instructs 
> Tomcat to do so, of course).
> Yes, I know I'm "not supposed to do this" and that the servlet spec 
> says a container is allowed to unload a server any time as long as a 
> request is not in process.  I still would like to know if there's some 
> Tomcat specific way to tell TC7 to never unload the servlet. And yes, 
> I realize even if there is such a way that future versions of Tomcat 
> may remove this capability.  :)

You have said both "servlet" and "server": which did you mean?

Do you need a particular web application to stay loaded? That's easy:
simply don't undeploy it.

Do you need a single (or multiple) servlet(s) to stay loaded all the time? That's also easy:
I don't believe Tomcat ever actually unloads a servlet. (You can easily test this by implementing
the destroy() method and emitting some kind of log).

What is it about the servlet that it needs to stay loaded? Servlets aren't really supposed
to have any state, so unloading and re-loading the servlet shouldn't represent anything traumatic
to your web application.

If you have to have some kind of data loaded all the time, consider moving that data into
the ServletContext (aka "application")
attributes: then the servlet can be unloaded and re-loaded at will and the data will persist.

- -chris
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools -
Comment: Using GnuPG with Mozilla -


To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message