You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Richard Sand <rs...@vgalleries.com> on 2002/01/07 04:32:51 UTC

how close static resources when an application is stopped/reloaded?

Hi all-

I have a web application that uses some static resources to make them available to any class in the application.  Amongst these static resources is a home-brewed JDBC connection pool.  What I'm seeing is that with Tomcat 4, when I stop/start or reload an application from the manager app, it isn't freeing up these static resources.  I can see this because my memory utilization goes up about 5 megs every time I restart, whereas if I stop and restart the whole tomcat process, my memory stays the same.  Also the database starts yelling at me about too many applications simultaneously etc.

How can I tell Tomcat to clean up these resources when it stops the application? What hook/mechanism is there?  Is there some sort of listener interface I can implement, similar in idea to an HttpSessionBindingEvent, to let me know when an application is shutting down so I can close all of the database connections?

None of this was an issue in Tomcat 3.x because I had no choice but to shut down the entire tomcat instance!

Any help greatly appreciated!  Thanks!

Best regards,

Richard

Re: how close static resources when an application is stopped/reloaded?

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Mon, 7 Jan 2002, Richard Sand wrote:

> Date: Mon, 7 Jan 2002 18:59:29 +0100
> From: Richard Sand <rs...@vgalleries.com>
> Reply-To: Tomcat Users List <to...@jakarta.apache.org>
> To: Tomcat Users List <to...@jakarta.apache.org>
> Subject: Re: how close static resources when an application is
>     stopped/reloaded?
>
> Thanks Craig and sorry for the RTFM- I'm still catching up with the new
> stuff in 2.3!
>

No problem -- it's nice to see use cases that prove we were on the right
track in designing the new features!  :-)

> BTW do you have an opinion on the new behavior of 4.0 to treat resources
> loaded through the classloader the same as classes- i.e. they are cached and
> cannot be changed unless the app is restarted?

You're probably not going to like it, but I think this is the correct
behavior for Tomcat to implement.  (It's not a spec issue in this case,
because application reloading is a value-added feature not a required
thing.)

>  I ask because all of my apps
> use an application management tool that keeps application configuration
> parameters in a .properties file, and typically I've been able to change the
> properties without restarting anything.  Now with 4.0 these files are
> treated just like classes, so changes cannot be picked up unless the app is
> restarted.  I had opened up a bug report on this behavior and the developer
> replied that this is how he wanted to do it and that it wouldn't change.
>
> I pointed out that this isn't the behavior I've seen on other app servers.
> What do you think of this behavior?
>

Per above, I think that *everything* loaded by a class loader should be
treated in a consistent manner.  It's too confusing to treat things
differently, and would cause a performance penalty to change to the
behavior you suggest (because the conatiner wouldn't be able to cache
existing resources).

> Thanks!
>
> -Richard
>

Craig


--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>


Re: how close static resources when an application is stopped/reloaded?

Posted by Richard Sand <rs...@vgalleries.com>.
Thanks Craig and sorry for the RTFM- I'm still catching up with the new
stuff in 2.3!

BTW do you have an opinion on the new behavior of 4.0 to treat resources
loaded through the classloader the same as classes- i.e. they are cached and
cannot be changed unless the app is restarted?  I ask because all of my apps
use an application management tool that keeps application configuration
parameters in a .properties file, and typically I've been able to change the
properties without restarting anything.  Now with 4.0 these files are
treated just like classes, so changes cannot be picked up unless the app is
restarted.  I had opened up a bug report on this behavior and the developer
replied that this is how he wanted to do it and that it wouldn't change.

I pointed out that this isn't the behavior I've seen on other app servers.
What do you think of this behavior?

Thanks!

-Richard

----- Original Message -----

> Doing this is exactly what the new application event listeners APIs (in
> Servlet 2.3) are designed for.  You need to:
>
> * Create a class that implements javax.servlet.ServletContextListener
>
> * Register it (in web.xml> with a <listener> element
>
> * In the contextInitialized() method, set up your connection pool
>
> * In the contextDestroyed() method, gracefully clean up your
>   connection pool.
>
> Craig
>



--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>


Re: how close static resources when an application is stopped/reloaded?

Posted by "Craig R. McClanahan" <cr...@apache.org>.
On Mon, 7 Jan 2002, Richard Sand wrote:

> Date: Mon, 7 Jan 2002 04:32:51 +0100
> From: Richard Sand <rs...@vgalleries.com>
> Reply-To: Tomcat Users List <to...@jakarta.apache.org>
> To: tomcat-user@jakarta.apache.org
> Subject: how close static resources when an application is
>     stopped/reloaded?
>
> Hi all-
>
> I have a web application that uses some static resources to make them
> available to any class in the application.  Amongst these static
> resources is a home-brewed JDBC connection pool.  What I'm seeing is
> that with Tomcat 4, when I stop/start or reload an application from the
> manager app, it isn't freeing up these static resources.  I can see this
> because my memory utilization goes up about 5 megs every time I restart,
> whereas if I stop and restart the whole tomcat process, my memory stays
> the same.  Also the database starts yelling at me about too many
> applications simultaneously etc.
>
> How can I tell Tomcat to clean up these resources when it stops the
> application? What hook/mechanism is there?  Is there some sort of
> listener interface I can implement, similar in idea to an
> HttpSessionBindingEvent, to let me know when an application is shutting
> down so I can close all of the database connections?
>
> None of this was an issue in Tomcat 3.x because I had no choice but to
> shut down the entire tomcat instance!
>
> Any help greatly appreciated!  Thanks!
>
> Best regards,
>
> Richard
>

Doing this is exactly what the new application event listeners APIs (in
Servlet 2.3) are designed for.  You need to:

* Create a class that implements javax.servlet.ServletContextListener

* Register it (in web.xml> with a <listener> element

* In the contextInitialized() method, set up your connection pool

* In the contextDestroyed() method, gracefully clean up your
  connection pool.

Craig



--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>