-----------------------------
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.
>
> Are you sure you are not calling destroy() on it yourself? If you are, by
> the way, that's really bad -- because your servlet will think it was
> destroyed but Apache JServ will not know about it, and will call destroy()
> again later, thus breaking the servlet API contracts.
I do not call destroy. Does JServ clean up unused servlets or not? It
looks to me like this and if yes, why is it cleaning up a servlet
running as a thread.
>
> >
> > Is there a way to solve such issues, where you want to leave Objects
> > loaded?
> >
>
> Another approach would be to make "Globals" a non-servlet class, and use
> static initializers to set things up the first time it is referenced.
> You'd still want to reference it from a startup servlet to make sure this
> happens ahead of normal use.
But that's my point, actually this is exactly what I'm doing, but it
seems the servlet get's unloaded. Yes I think we take advantage of
automatic reloading, but I did not compile anything, so it should stay
loaded right?
thx for the reply.
mcfly
--
--------------------------------------------------------------
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]