actually im already using a class extending servletcontextlistener, this class is the responsible to start all other threads on processing. Some threads stores results on a DB, some threads should store results in an object to be accesed by a servlet and presented via web.
If i use the a) approach and i use it as Listener, how can i access this class from other threads/classes on my webapp? thanks again On Jan 30, 2011, at 10:32 PM, Brett Delle Grazie wrote: > Hi, > > On 31 January 2011 00:37, alexis <alz...@gmail.com> wrote: >> Hello, if i need to share a custom class (that instantiate other clases) >> within my webapp, where multiple threads need to access this class to read >> and write (via synchronized methods), how can achieve this? > > It sounds like your class is representative of a factory pattern, > albeit with some synchronisation. Is this correct? > > If so, you could: > (a) Use a ServletContextListener to instantiate the class. It will > need to be defined in your web.xml appropriately. > This is an appropriate place to 'shutdown' the factory as well. > or > (b) Use one of the many frameworks that instantiate stuff for you. > e.g. Spring Framework. Spring will do this > in a webapp, standalone or testing context with no change to your > actual class. To the best of my > knowledge, most inversion-of-control frameworks (like Spring) use the > ServletContextListener approach for > instantiation in a web application. > > If you go for option (b) you should consider whether simply to use the > framework only and drop your factory > class (if that's possible). > >> >> thanks >> > > -- > Best Regards, > > Brett > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org > For additional commands, e-mail: users-h...@tomcat.apache.org > --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org