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

Discussion in 'Java' started by efiedler, Jul 8, 2003.

  1. efiedler

    efiedler Guest

    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
     
    efiedler, Jul 8, 2003
    #1
    1. Advertising

  2. efiedler

    Ben_ Guest

    > 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 ?
     
    Ben_, Jul 8, 2003
    #2
    1. Advertising

  3. efiedler wrote:
    > 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
     
    John C. Bollinger, Jul 8, 2003
    #3
  4. efiedler

    Phil Hanna Guest

    On 8 Jul 2003 10:57:56 -0700, (efiedler) wrote:

    >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.
    --
    Phil Hanna
    Author of JSP 2.0: The Complete Reference
    http://www.philhanna.com
    http://www.philhanna.com
     
    Phil Hanna, Jul 9, 2003
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andy
    Replies:
    1
    Views:
    2,015
    Chris Taylor
    Sep 24, 2005
  2. Andy

    Cant unload assembly

    Andy, Oct 12, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    1,860
    Nick Hertl
    Oct 18, 2005
  3. M N E E L Y
    Replies:
    3
    Views:
    474
    Natty Gur
    Jul 16, 2003
  4. maxwell

    servelt newbie question

    maxwell, Feb 20, 2004, in forum: Java
    Replies:
    18
    Views:
    710
    steve r. burrus
    Feb 26, 2004
  5. Peña, Botp
    Replies:
    1
    Views:
    261
    Robert Klemme
    Jan 24, 2004
Loading...

Share This Page