You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Cherry Development <av...@cherrydev.com> on 2004/08/04 23:48:06 UTC

Clean tapestry application shutdown?

I'd like to suggest that we make a few simple additions to Tapestry so 
that a tapestry servlet can be stopped and restarted cleanly.

I've been cleaning up my application so that a servlet.destroy() 
actually cleans up everything so that the servlet container doesn't 
need to be restarted each time the web application gets updated.  This 
is what I've had to do:

I've sub-classed ApplicationServlet so that it implements destroy().  I 
have it calling a hook that runs any user-defined cleanup tasks.
One thing I can't do, easily, is to stop the JanitorThread.  There is 
currently no clean way to stop it.  I can call stop() on the thread, 
but that's probably a really bad idea since stop() is deprecated and it 
generates an uncaught exception.  A simple change to give JanitorThread 
a cleanup method should fix this.  I think that ApplicationServlet 
should automatically stop the JanitorThread from within the destroy() 
method, either before or after calling the user-defined cleanup hooks.

A cleanup hook could be implemented with a configuration property that 
defines a Runnable class to be instantiated and ran at cleanup time.

Ideas?  Comments?


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Clean tapestry application shutdown?

Posted by Cherry Development <av...@cherrydev.com>.
I feel that directly calling interrupt() is a pretty low-level way of 
doing it.  I prefer a higher-level mechanism that may, in its 
operation, call interrupt directly.
However it's done, it's only going to be a few lines of code.

On Aug 4, 2004, at 3:22 PM, Paul Ferraro wrote:

> I think the cleanest way to stop the running JanitorThread is to use 
> the interrupt mechanism:


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Clean tapestry application shutdown?

Posted by Paul Ferraro <pm...@columbia.edu>.
I think the cleanest way to stop the running JanitorThread is to use the 
interrupt mechanism:
// ApplicationServlet.java
    public void destroy()
    {
        if (_registry != null)
        {
            _registry.shutdown();
            _registry = null;
        }

        JanitorThread.getSharedJanitorThread().interrupt();
    }

To support this, JanitorThread.run() needs to be modified:
// JanitorThread.java
    public void run()
    {
        while (!this.isInterrupted())
        {
            waitForNextPass();

            sweep();
        }
    }

and JanitorThread.waitForNextPass() becomes:
// JanitorThread.java
    protected void waitForNextPass()
    {
        try
        {
            sleep(interval);
        }
        catch (InterruptedException ex)
        {
            // Set this thread's interrupted status
            this.interrupt();
        }
    }

Thoughts?

Paul

Cherry Development wrote:

> I'd like to suggest that we make a few simple additions to Tapestry so 
> that a tapestry servlet can be stopped and restarted cleanly.
>
> I've been cleaning up my application so that a servlet.destroy() 
> actually cleans up everything so that the servlet container doesn't 
> need to be restarted each time the web application gets updated.  This 
> is what I've had to do:
>
> I've sub-classed ApplicationServlet so that it implements destroy().  
> I have it calling a hook that runs any user-defined cleanup tasks.
> One thing I can't do, easily, is to stop the JanitorThread.  There is 
> currently no clean way to stop it.  I can call stop() on the thread, 
> but that's probably a really bad idea since stop() is deprecated and 
> it generates an uncaught exception.  A simple change to give 
> JanitorThread a cleanup method should fix this.  I think that 
> ApplicationServlet should automatically stop the JanitorThread from 
> within the destroy() method, either before or after calling the 
> user-defined cleanup hooks.
>
> A cleanup hook could be implemented with a configuration property that 
> defines a Runnable class to be instantiated and ran at cleanup time.
>
> Ideas?  Comments?
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org