how to determine when a servelt will unload????

E

efiedler

Hi -

I have a webpage that utilizes a servlet (written in JBuilder 7 and is
ran under Tomcat 4.0)...is there a way to find out how long of an idle
time is allowed (no calls to the servlet from the client) before the
servlet will be unloaded by Tomcat? And if I can find this out, can I
set this value somehow.

I have tried using the session.setmaxintervaltime but that does not
seem to work.

I would like to be able to kill the servlet after some set amount of
time so that I can run some code in the servelts destory method.

Thanks
 
B

Ben_

I have a webpage that utilizes a servlet (written in JBuilder 7 and is
ran under Tomcat 4.0)...is there a way to find out how long of an idle
time is allowed (no calls to the servlet from the client) before the
servlet will be unloaded by Tomcat? And if I can find this out, can I
set this value somehow.

It's implementation dependent, see the Servlet Specification:
SRV.2.3.4 End of Service
The servlet container is not required to keep a servlet loaded for any
particular
period of time. A servlet instance may be kept active in a servlet container
for a
period of milliseconds, for the lifetime of the servlet container (which
could be a
number of days, months, or years), or any amount of time in between.
When the servlet container determines that a servlet should be removed from
service, it calls the destroy method of the Servlet interface to allow the
servlet to
release any resources it is using and save any persistent state. For
example, the
container may do this when it wants to conserve memory resources, or when it
is
being shut down.
Before the servlet container calls the destroy method, it must allow any
threads that are currently running in the service method of the servlet to
complete
execution, or exceed a server-defined time limit.
Once the destroy method is called on a servlet instance, the container may
not route other requests to that instance of the servlet. If the container
needs to
enable the servlet again, it must do so with a new instance of the servlet's
class.
After the destroy method completes, the servlet container must release the
servlet instance so that it is eligible for garbage collection.
I have tried using the session.setmaxintervaltime but that does not
seem to work.
Do not confuse Servlet life-cycle with session life-cycle.
I would like to be able to kill the servlet after some set amount of
time so that I can run some code in the servelts destory method.
What for ?
 
J

John C. Bollinger

efiedler said:
I would like to be able to kill the servlet after some set amount of
time so that I can run some code in the servelts destory method.

Then you are using the wrong tool for the job. If you explain the
bigger picture of what you want to accomplish then perhaps we can
suggest some alternatives.


John Bollinger
(e-mail address removed)
 
P

Phil Hanna

Hi -

I have a webpage that utilizes a servlet (written in JBuilder 7 and is
ran under Tomcat 4.0)...is there a way to find out how long of an idle
time is allowed (no calls to the servlet from the client) before the
servlet will be unloaded by Tomcat? And if I can find this out, can I
set this value somehow.

I have tried using the session.setmaxintervaltime but that does not
seem to work.

That's because this applies only to a particular user's session. If
the servlet is never called, there are no sessions.
I would like to be able to kill the servlet after some set amount of
time so that I can run some code in the servelts destory method.

Thanks

You shouldn't care whether a servlet is loaded or not; that's the
container's job. If you only care about the time interval since the
last call to the servlet, you can start a background thread in the
init() method that runs the code after a specified wait time. Every
time the servlet is called, you can reset this thread's countdown time
(with a synchronized method call) so that it only times out when there
has been no client activity.

You shouldn't put the code you want to run in the destroy() method,
either, because you have no way to control when destroy() is run. If
you really want it run after a certain period of time with no
activity, check that yourself as described above.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top