tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alexis <alz...@gmail.com>
Subject Re: custom class as resource
Date Mon, 31 Jan 2011 01:40:03 GMT
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 <alzrck@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-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 


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


Mime
View raw message