Hi all,
I have few doubts to be clarified in designing our Web framework. I will
appreciate, if you can provide me the guidance in the following issues
regarding Singleton.
1. How to use Singletons ? :
I have few Singleton classes like DBConnectionPoolManager. I would like to
know, what is the right way of using this class. For example, just before we
need a Connection object, can we call ConnectionPoolManager.getInstance()
and then call the getConnection() method ? That means for every servlet
which accesses the database, there will be a new instance of this Singleton
? But is it not that we need to have one instance for the whole of
application irrespective of pages ? Where and when do we need to instantiate
this DBConnectionPoolManager class ? It has to be at the application
start-up time, right ? But how ?
2. I have a ConfigurationManager, which basically will get all the setting
properties from a single .properties file. For example, for
DBConnectionManager, it gets the properties of driver, URL, user-id and
password; for mailing services, it gets the properties like SMTP host, port,
etc., I want to know whether this ConfigurationManager has to be a
singleton ? Since there is only one .properties file for all the
configuration properties like database, mail, etc., whether it is required
that ConfigurationManager has to be a Singleton ? I will get all the
properties at initialization time and load the properties as an in-memory
object. That way, it is not required to be a Singleton, right ?
3. I also have a LogWriter Class. Again all my logging should go to only one
log file (basically a .txt file) based on the debug level with timestamp. So
from any part of the application, say any JSP, I need to call LogWriter
class for writeLog(String str) method. Should I design this a Singleton ? If
not, how do I ensure that many instances of this class doesn't create many
instances of the log file ?
Thank you,
Raj
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html