Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » J2EE Interest »

Re: Singleton class issue

Partha Ranjan Das

2004-11-18

Replies:

RE: Singleton class issue

Hi,

It is best to have a single connection and associated objects like statement, resultset etc for a single thread. Hence, for multi-threaded access, you may create your DAO layer like this:

have a singleton DAOFactory class having a static getInstance() method returning a single DAOFactory instance. This class will create DAO objects through its instance methods. Each of these DAO objects will have a connection as a private field. This connection will be picked up from the app server created pool. The client will call like this: call the DAOFactory.getInstance() and on the returned instance call the getDAO() method which will return a new DAO instance each time. ANd then work with that DAO object which is unique for a unique thread or request.

Hope you are able to understand.

Regards,
Partha

=========================================================================== To unsubscribe, send email to listserv@java.sun.com and include in the body of the message "signoff J2EE-INTEREST". For general help, send email to listserv@java.sun.com and include in the body of the message "help".

©2008 junlu.com - Jax Systems, LLC, U.S.A.