RE: Listener Shutdown Order?

2007-11-15 Thread Jim Garrison


 -Original Message-
 From: Christopher Schultz [mailto:[EMAIL PROTECTED]
 Sent: Wednesday, November 14, 2007 12:34 PM
 To: Tomcat Users List
 Subject: Re: Listener Shutdown Order?
 
 -BEGIN PGP SIGNED MESSAGE-
 Hash: SHA1
 
 Jim,
 
 Jim Garrison wrote:
  From: Christopher Schultz [mailto:[EMAIL PROTECTED]
 
  Notification that the servlet context is *about* to be shut down.
All
  servlets and filters have been destroy()ed before any
  ServletContextListeners are notified of context destruction.
 
  What I'm seeing is that servlet destroy() is being called AFTER the
  listeners have been shutdown.  If I'm reading the quote above right,
  this shouldn't happen; servlets should have already been destroy()ed
  before the listener is shutdown.
 
 
 I checked the Tomcat 5.5 source, and this is what happens in
 StandardContext.stop():
 
 .
 .
 .

You are, of course, correct and there is no bug.  I was getting confused
due to multiple contexts running in a single server.  I've sorted
everything out now and it all appears to work as expected.

The root cause of my confusion was a bug in the Eclipse debugger's
variable-value tooltip display, which can display the wrong value if
there are two instances of a Class loaded under different classloaders.

IMPORTANT NOTICE:
This message may contain confidential information. If you have received this 
e-mail in error, do not use, copy or distribute it. Do not open any 
attachments. Delete it immediately from your system and notify the sender 
promptly by e-mail that you have done so. Thank you.


-
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Listener Shutdown Order?

2007-11-14 Thread Jim Garrison
When starting up, Listeners are started before load-on-startup servlets,
so we use this mechanism to initialize Spring.

 

On shutdown, Tomcat seems to shutdown listeners BEFORE the servlets.
This results in the Spring context being discarded while it is still
needed.  If context listeners start before servlets, shouldn't the
listeners be shutdown AFTER the servlets?


IMPORTANT NOTICE:
This message may contain confidential information. If you have received this 
e-mail in error, do not use, copy or distribute it. Do not open any 
attachments. Delete it immediately from your system and notify the sender 
promptly by e-mail that you have done so. Thank you.



Re: Listener Shutdown Order?

2007-11-14 Thread Christopher Schultz
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Jim,

Jim Garrison wrote:
 When starting up, Listeners are started before load-on-startup servlets,
 so we use this mechanism to initialize Spring.

So you are using a ServletContextListener, right?

 On shutdown, Tomcat seems to shutdown listeners BEFORE the servlets.
 This results in the Spring context being discarded while it is still
 needed.  If context listeners start before servlets, shouldn't the
 listeners be shutdown AFTER the servlets?

The Servlet Specification covers this a bit in section 10.3.4 (of 2.4...
I can't seem to find the actual PDF for the 2.5 spec), but does not
specify that the context must be shut down before the listeners are
notified. (In fact, it doesn't make any sense that it would happen this
way... the listeners exist within the context, so terminating the
context and then notifying the listeners is a bit of an odd notion).

The javadoc for ServletContextListener.contextDestroyed clearly
indicates that the message is sent /before/ the context is actually
destroyed:

Notification that the servlet context is *about* to be shut down. All
servlets and filters have been destroy()ed before any
ServletContextListeners are notified of context destruction. (Emphasis
added by me).

Note that the implication of this documentation is that the context will
not be serving any more requests by the time your listener is notified,
do you don't really have to worry about Spring not being available to
your servlets and stuff, 'cause they've already been taken out of service.

Were you experiencing a problem, or just anticipating one?

Hope that helps,
- -chris

-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD4DBQFHOzOv9CaO5/Lv0PARAn3pAJ9ObkpOysp3n9nS7JW50oS8EzcbEACXZrOB
1uiI3HXLQQkA8nL2H4mgmg==
=lF29
-END PGP SIGNATURE-

-
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Listener Shutdown Order?

2007-11-14 Thread Jim Garrison


 -Original Message-
 From: Christopher Schultz [mailto:[EMAIL PROTECTED]
 Sent: Wednesday, November 14, 2007 11:43 AM
 
 Notification that the servlet context is *about* to be shut down. All
 servlets and filters have been destroy()ed before any
 ServletContextListeners are notified of context destruction.

What I'm seeing is that servlet destroy() is being called AFTER the
listeners have been shutdown.  If I'm reading the quote above right,
this shouldn't happen; servlets should have already been destroy()ed
before the listener is shutdown.  

The problem is that the non-Spring servlet needs to notify a Spring
based component to shutdown, and can't get to it after the Spring
ApplicationContext is gone.

BTW, thanks for the quick reply.


IMPORTANT NOTICE:
This message may contain confidential information. If you have received this 
e-mail in error, do not use, copy or distribute it. Do not open any 
attachments. Delete it immediately from your system and notify the sender 
promptly by e-mail that you have done so. Thank you.


-
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Listener Shutdown Order?

2007-11-14 Thread Christopher Schultz
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Jim,

Jim Garrison wrote:
 From: Christopher Schultz [mailto:[EMAIL PROTECTED]
 
 Notification that the servlet context is *about* to be shut down.
 All servlets and filters have been destroy()ed before any 
 ServletContextListeners are notified of context destruction.
 
 What I'm seeing is that servlet destroy() is being called AFTER the 
 listeners have been shutdown.  If I'm reading the quote above right, 
 this shouldn't happen; servlets should have already been destroy()ed 
 before the listener is shutdown.

Hmm. How are you observing this? Logging statements? Do they have
timestamps? I'm wondering if you're potentially seeing things out of
order. Otherwise, this is a bug in Tomcat. Which version?

 The problem is that the non-Spring servlet needs to notify a Spring 
 based component to shutdown, and can't get to it after the Spring 
 ApplicationContext is gone.

Wait.. what is trying to notify what in this scenario. Shouldn't the
ServletContextListener be the one sending the shutdown message? Don't
you initialize Spring in the same ServletContextListener? If that's the
case, keep a reference to whatever you need in the
ServletContextListener object and then use it directly instead of trying
to get that object from somewhere else.

- -chris

-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHOz2u9CaO5/Lv0PARAqAZAJ40WTchkvVsDaQUwJJ6ur22iZ1ogwCgrSF6
V9uDUV44qmivx48r3v0WRKU=
=nW2U
-END PGP SIGNATURE-

-
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Listener Shutdown Order?

2007-11-14 Thread Christopher Schultz
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Jim,

Jim Garrison wrote:
 From: Christopher Schultz [mailto:[EMAIL PROTECTED]

 Notification that the servlet context is *about* to be shut down. All
 servlets and filters have been destroy()ed before any
 ServletContextListeners are notified of context destruction.
 
 What I'm seeing is that servlet destroy() is being called AFTER the
 listeners have been shutdown.  If I'm reading the quote above right,
 this shouldn't happen; servlets should have already been destroy()ed
 before the listener is shutdown.  


I checked the Tomcat 5.5 source, and this is what happens in
StandardContext.stop():

.
.
.
// Stop our child containers, if any
Container[] children = findChildren();
for (int i = 0; i  children.length; i++) {
if (children[i] instanceof Lifecycle)
((Lifecycle) children[i]).stop();
}

// Stop our filters
filterStop();

// Stop our application listeners
listenerStop();
.
.
.

In this case, children refers to the servlets and stuff like that
(actually wrappers thereof). The stopping does not look threaded, so I
can only assume that either the logging is playing tricks on you, or one
of your components is doing something strange like threading its own
shutdown.

- -chris
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHOz+T9CaO5/Lv0PARAoPDAJ9keKihPpFixoRST+K9bXQ+huvpQQCguEhF
5NXTdxJsZ7O79w+PZg5acQs=
=8Pyj
-END PGP SIGNATURE-

-
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]