You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Chris Longfield <cl...@mail.merrillhall.com> on 2001/01/05 20:35:43 UTC

[BUG] PropertyResourceBundle persisting outside servlet

Hello,
  I am not sure if this is a bug or not.  If not, perhaps you could explain why it happens.  I am using Apache-1.3.14, the jserv module 1.1.2, and tomcat 3.2.1 .  The HelloWorldExample uses a property resource bundle to fill in some data.  If you execute the servlet once, and then remove the property files, a second execution of the servlet works fine - even though it should not be able to instantiate the resource bundles.  Conversely, if you run the servlet when the properties files are not there a MissingResourceException is thrown.  Once you have run the servlet, replacing the properties files does not help.  The exception is still thrown.  Only after Tomcat is brought down and restarted will it behave properly.  This is a problem if one is trying to use properties files to dynamically change content without having to recompile classes.  
  Is this a bug, or is there a reason tomcat behaves this way?

Chris Longfield
clongfield@merrillhall.com

Re: [BUG] PropertyResourceBundle persisting outside servlet

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
Chris Longfield wrote:

> Hello,
>   I am not sure if this is a bug or not.  If not, perhaps you could explain why it happens.  I am using Apache-1.3.14, the jserv module 1.1.2, and tomcat 3.2.1 .  The HelloWorldExample uses a property resource bundle to fill in some data.  If you execute the servlet once, and then remove the property files, a second execution of the servlet works fine - even though it should not be able to instantiate the resource bundles.  Conversely, if you run the servlet when the properties files are not there a MissingResourceException is thrown.  Once you have run the servlet, replacing the properties files does not help.  The exception is still thrown.  Only after Tomcat is brought down and restarted will it behave properly.  This is a problem if one is trying to use properties files to dynamically change content without having to recompile classes.
>   Is this a bug, or is there a reason tomcat behaves this way?
>

What you're seeing is probably based on the fact that java.util.PropertyResourceBundle instances are cached in memory the first time they are accessed, just like a class file is.  Any changes that happen to the underlying files in the classpath are not relevant, because the loader always finds the resource or class in memory already first.

Same thing happens in any Java application, not just a servlet container.  Consider the following scenario:
* You write a simple Java application Foo
* You execute Foo from the command line,
  and (while it is still running) delete Foo.class
* Everything continues to work normally
  until the JVM exits.

In Tomcat's case, you'll see similar behavior if you delete a servlet's .class file after it's been loaded -- the class bytecodes are already in memory, so the fact that the file is no longer on disk is not relevant.


>
> Chris Longfield
> clongfield@merrillhall.com
>

Craig McClanahan