-----------------------------
Please read the FAQ!
<http://java.apache.org/faq/>
-----------------------------

Martin Roeder wrote:

> -----------------------------
> Please read the FAQ!
> <http://java.apache.org/faq/>
> -----------------------------
>
> "Craig R. McClanahan" wrote:
>
> > > I have a servlet called Globals, which reads a config file and stores
> > > variables that can be accessed by other servlets.
> > > Now when the Globals servlet gets automatically started upon
> > > JServ-launch it reads the conf file and presents static methods to
> > > access the variables. After the session for this servlet times out, the
> > > servlet gets destroyed though and I have to reread the config file which
> > > takes too much time. Now a book tells me to make the servlet an allways
> > > running thread to make it persistent, but when I do this, the JServ
> > > engine still destroys the servlet if it's not called during the session
> > > timeout period.
> > >
> >
> > Unless it's been modified, the only circumstances when Apache JServ calls
> > the destroy() method of a servlet is when you are shutting it down, or when
> > you are taking advantage of the automatic reloading on changes to servlet
> > classes.  It is never based on when sessions expire, because other active
> > sessions might also be accessing that servlet.
>
> Yeah it looked to me like there was a timeout, if a servlet wasn't
> accessed for a period of time at all.
> However here is a small example and an explanation what happens:
> ...
> public class Globals{
>
>         public static String dummy = null;
>
>         public void doGet(...{
>
>           dummy = "Hey!";
>         }
> }
>
> Ok when I call this servlet the static variable obviously gets the
> string "Hey!" and for a period of time, I can call Globals.dummy and get
> "Hey!". But after a while it is null again.
> I have overriden the destroy method and logged a message to see if it
> get's called but nope.
> It looks to me as if the gc would just see the Globals servlet and
> decide that it's not needed anymore.
>

If you don't maintain any references to the Global class, or any instance of it,
then the garbage collector definitly has the right to collect it.  You can fix
this by maintaining a reference in some loaded servlet or something to an
instance of this class -- even if you only use static methods in the class to do
things.

Craig




--
--------------------------------------------------------------
Please read the FAQ! <http://java.apache.org/faq/>
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Archives and Other:  <http://java.apache.org/main/mail.html>
Problems?:           [EMAIL PROTECTED]

Reply via email to