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

Reply via email to