You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Jason Bucholtz <ja...@scs.uiuc.edu> on 2004/04/05 22:56:42 UTC

RE: Servlet Context Listener problem - Solved

Yoav,

Thanks for the quick response-  Found my error, and embarrassingly it was
a
simple logic problem.  My logger was only being initialized if it had not
been previously initialized by the JVM.  As such, within that logic block
the log messages were only being output the very first time the app
started
in a tomcat session.   So, it appeared that the  listener wasn't being
called, but in actuality it was doing exactly as it should.

Jason


Jason A. Bucholtz
jason@scs.uiuc.edu

SCS Computer Center
152 Noyes Lab
4-0560

On Mon, 5 Apr 2004, Shapira, Yoav wrote:

>
> Hi,
> A couple of quick notes as I have to run to a meeting:
> - I think your understanding of the spec is correct
> - What happens if you reload the app (not undeploy and redeploy, but
> reload) via the manager webapp?
> - Are you sure the undeploy is COMPLETELY done cleanly, and no threads
> from your own webapp are left behind?  For example, do you have to
> shutdown your log manager?
>
> Yoav Shapira
> Millennium Research Informatics
>
>
> >-----Original Message-----
> >From: Jason Bucholtz [mailto:jabuchol@scs.uiuc.edu]
> >Sent: Monday, April 05, 2004 3:04 PM
> >To: Tomcat Users List
> >Subject: Servlet Context Listener problem
> >
> >I am using tomcat 5.0.19 and am experiencing different behavior from a
> >servlet context listener than what is outlined in the servlet spec.
> My
> >expectation is that the listener methods  contextInitialized()  and
> >contextDestroyed() should be called respectively each time the
> application
> >is undeployed and redeployed.
> >
> >However, in practice it appears the methods are only called once per
> >tomcat session.  I have  a class that implements Servlet context
> listener
> >and the methods contextInitialized() and  contextDestroyed()  are only
> >called once and not on subsequent undeploys and redeploys.  However,
> >restarting tomcat causes the methods to be called again, but only for a
> >single deployment of the application.  Those methods are not called
> again
> >unless tomcat is restarted (I have also tried the reload task, start
> and
> >stop all with no success).
> >
> >That is, if the application is deployed and tomcat is restarted, the
> >method contextInitialized() is called, and if the app is undelpoyed the
> >method contextDestroyed() is also correctly called.  On any subsequent
> >deployments or undeployments the servlet context listener methods are
> not
> >called.  Restarting  tomcat always results in the methods being called
> >again on the first deployment or undeployment after the restart.
> >
> >First, is the witnessed behavior the way context listeners are supposed
> >behave?  If not, do you have any suggestions on where I might look to
> >correct the problem.
> >
> >
> >For completeness, I am including my listener tag from web.xml file and
> the
> >source of the class that implements ServletContextListener.
> >
> >
> >In my web.xml file I have registered the listener as follows:
> >
> ><listener>
> >     <listener class>
> >scs.reaction.common.init.ReactionInitialization
> ></listener-class>
> ></listener>
> >
> >
> >
> >And here is my implementation:
> >
> >
> >package scs.reaction.common.init;
> >import java.io.IOException;
> >import java.util.logging.*;
> >
> >import javax.servlet.*;
> >
> >public class ReactionInitialization implements ServletContextListener {
> >
> >	Logger logger = null;
> >
> >	public ReactionInitialization(){}
> >
> >	public void contextInitialized(ServletContextEvent arg0){
> >
> >		// Check to see if the root log manager for this
> >application exists if
> >		// not initialize it and set its default atributes
> >
> if(LogManager.getLogManager().getLogger("scs.reaction")==
> >null)
> >		{
> >
> >			//Call the supers initialization first
> >			// we will name all loggers after thier fully
> >qaulified class name
> >
> >			logger = Logger.getLogger("scs.reaction");
> >
> >			FileHandler fileHandler = null;
> >
> >
> >			//creare our own file handler
> >			// the file handler will cycle through 2 files
> >			// files are limited in size to 100KB and
> sessions
> >are appended
> >
> >			try {
> >				fileHandler = new
> >FileHandler(System.getProperty("catalina.home")+ "/logs/" +
> >"scs.reaction.log",1000000,2,true);
> >			} catch (SecurityException e) {
> >				e.printStackTrace();
> >			} catch (IOException e) {
> >				e.printStackTrace();
> >			}
> >
> >
> >			// use a standard text formatter for the file
> >output
> >			fileHandler.setFormatter(new SimpleFormatter());
> >			//attach the handler
> >			logger.addHandler(fileHandler);
> >			//Set the level to all messages
> >			logger.setLevel(Level.FINEST);
> >
> >			logger.finer("Context Intitalized");
> >
> >
> >
> >		}
> >
> >	}
> >
> >
> >	public void contextDestroyed(ServletContextEvent arg0) {
> >
> >		logger.finer("Context Destroyed");
> >
> >	}
> >
> >}
> >
> >
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> >For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
>
>
> This e-mail, including any attachments, is a confidential business communication, and may contain information that is confidential, proprietary and/or privileged.  This e-mail is intended only for the individual(s) to whom it is addressed, and may not be saved, copied, printed, disclosed or used by anyone else.  If you are not the(an) intended recipient, please immediately delete this e-mail from your computer system and notify the sender.  Thank you.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>

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


RE: Servlet Context Listener problem - Solved

Posted by Yansheng Lin <ya...@silvacom.com>.
hehe, that kind of thing happens(speaking from experience)
Glad you found the problem.  At first glance, I thought you found a bug in
tomcat 5:).

-----Original Message-----
From: Jason Bucholtz [mailto:jabuchol@scs.uiuc.edu] 
Sent: Monday, April 05, 2004 2:57 PM
To: Tomcat Users List
Subject: RE: Servlet Context Listener problem - Solved


Yoav,

Thanks for the quick response-  Found my error, and embarrassingly it was
a
simple logic problem.  My logger was only being initialized if it had not
been previously initialized by the JVM.  As such, within that logic block
the log messages were only being output the very first time the app
started
in a tomcat session.   So, it appeared that the  listener wasn't being
called, but in actuality it was doing exactly as it should.

Jason


Jason A. Bucholtz
jason@scs.uiuc.edu

SCS Computer Center
152 Noyes Lab
4-0560

On Mon, 5 Apr 2004, Shapira, Yoav wrote:

>
> Hi,
> A couple of quick notes as I have to run to a meeting:
> - I think your understanding of the spec is correct
> - What happens if you reload the app (not undeploy and redeploy, but
> reload) via the manager webapp?
> - Are you sure the undeploy is COMPLETELY done cleanly, and no threads
> from your own webapp are left behind?  For example, do you have to
> shutdown your log manager?
>
> Yoav Shapira
> Millennium Research Informatics
>
>
> >-----Original Message-----
> >From: Jason Bucholtz [mailto:jabuchol@scs.uiuc.edu]
> >Sent: Monday, April 05, 2004 3:04 PM
> >To: Tomcat Users List
> >Subject: Servlet Context Listener problem
> >
> >I am using tomcat 5.0.19 and am experiencing different behavior from a
> >servlet context listener than what is outlined in the servlet spec.
> My
> >expectation is that the listener methods  contextInitialized()  and
> >contextDestroyed() should be called respectively each time the
> application
> >is undeployed and redeployed.
> >
> >However, in practice it appears the methods are only called once per
> >tomcat session.  I have  a class that implements Servlet context
> listener
> >and the methods contextInitialized() and  contextDestroyed()  are only
> >called once and not on subsequent undeploys and redeploys.  However,
> >restarting tomcat causes the methods to be called again, but only for a
> >single deployment of the application.  Those methods are not called
> again
> >unless tomcat is restarted (I have also tried the reload task, start
> and
> >stop all with no success).
> >
> >That is, if the application is deployed and tomcat is restarted, the
> >method contextInitialized() is called, and if the app is undelpoyed the
> >method contextDestroyed() is also correctly called.  On any subsequent
> >deployments or undeployments the servlet context listener methods are
> not
> >called.  Restarting  tomcat always results in the methods being called
> >again on the first deployment or undeployment after the restart.
> >
> >First, is the witnessed behavior the way context listeners are supposed
> >behave?  If not, do you have any suggestions on where I might look to
> >correct the problem.
> >
> >
> >For completeness, I am including my listener tag from web.xml file and
> the
> >source of the class that implements ServletContextListener.
> >
> >
> >In my web.xml file I have registered the listener as follows:
> >
> ><listener>
> >     <listener class>
> >scs.reaction.common.init.ReactionInitialization
> ></listener-class>
> ></listener>
> >
> >
> >
> >And here is my implementation:
> >
> >
> >package scs.reaction.common.init;
> >import java.io.IOException;
> >import java.util.logging.*;
> >
> >import javax.servlet.*;
> >
> >public class ReactionInitialization implements ServletContextListener {
> >
> >	Logger logger = null;
> >
> >	public ReactionInitialization(){}
> >
> >	public void contextInitialized(ServletContextEvent arg0){
> >
> >		// Check to see if the root log manager for this
> >application exists if
> >		// not initialize it and set its default atributes
> >
> if(LogManager.getLogManager().getLogger("scs.reaction")==
> >null)
> >		{
> >
> >			//Call the supers initialization first
> >			// we will name all loggers after thier fully
> >qaulified class name
> >
> >			logger = Logger.getLogger("scs.reaction");
> >
> >			FileHandler fileHandler = null;
> >
> >
> >			//creare our own file handler
> >			// the file handler will cycle through 2 files
> >			// files are limited in size to 100KB and
> sessions
> >are appended
> >
> >			try {
> >				fileHandler = new
> >FileHandler(System.getProperty("catalina.home")+ "/logs/" +
> >"scs.reaction.log",1000000,2,true);
> >			} catch (SecurityException e) {
> >				e.printStackTrace();
> >			} catch (IOException e) {
> >				e.printStackTrace();
> >			}
> >
> >
> >			// use a standard text formatter for the file
> >output
> >			fileHandler.setFormatter(new SimpleFormatter());
> >			//attach the handler
> >			logger.addHandler(fileHandler);
> >			//Set the level to all messages
> >			logger.setLevel(Level.FINEST);
> >
> >			logger.finer("Context Intitalized");
> >
> >
> >
> >		}
> >
> >	}
> >
> >
> >	public void contextDestroyed(ServletContextEvent arg0) {
> >
> >		logger.finer("Context Destroyed");
> >
> >	}
> >
> >}
> >
> >
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> >For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
>
>
> This e-mail, including any attachments, is a confidential business
communication, and may contain information that is confidential, proprietary
and/or privileged.  This e-mail is intended only for the individual(s) to whom
it is addressed, and may not be saved, copied, printed, disclosed or used by
anyone else.  If you are not the(an) intended recipient, please immediately
delete this e-mail from your computer system and notify the sender.  Thank you.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>

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


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