On Fri, 7 Dec 2001, Chris Williamson wrote: > Date: Fri, 7 Dec 2001 16:19:02 -0600 > From: Chris Williamson <[EMAIL PROTECTED]> > Reply-To: Tomcat Users List <[EMAIL PROTECTED]> > To: Tomcat Users Group <[EMAIL PROTECTED]> > Subject: Resources > > Is there a way to load an object into Tomcat, have it initialize > automatically, then sit back and process requests. > > For example you could do this using an MBean in JBoss. I am looking for a > similar solution using Tomcat. > > I can load a resource but it creates a new object everytime I try to look up > the object in JNDI. I would rather it just reference an object that is > initialized when the system starts. > > Anyway to do this? > > Thanks for any help, > > Chris >
In a Servlet 2.3 environment (like Tomcat 4), one approach to this would be the new application event listeners functionality. You can register a listener (implements ServletContextListener) that is notified when the web application is started up and shut down. At startup time, simply create the resource you want, and stick it in the servlet context attributes. For Tomcat 4 specifically, you can also create your own object factory for JNDI-accessed resources. The implementation of this factory is totally up to you, so you could have it create an object once and return it every time. (Also, in an update that will show up in 4.0.2 soon, the standard object factories only create an object once.) Craig -- To unsubscribe: <mailto:[EMAIL PROTECTED]> For additional commands: <mailto:[EMAIL PROTECTED]> Troubles with the list: <mailto:[EMAIL PROTECTED]>
