Hi,
I have a struts application that creates a DAO factory on application initialisation.
The DAO factory is initialised with a DataSource instance like this
private IDAOFactory getDaoFactory() throws InitialisationError
{
logger.debug(IConstants.ENTERING);
IDAOFactory daoFactory = null;
if(IConstants.JDBC_DAO_FACTORY.equals(getDaoFactoryType()))
{
daoFactory = new JDBCDaoFactory(getDataSource());
}
logger.debug(IConstants.EXITING);
return daoFactory;
}
Once the DAO factory is retrieved it is passed to a DAOHelper class like this
DAOHelper.setDaoFactory(getDaoFactory());
The DAOHelper class has two methods:
public static IDAOFactory getDaoFactory()
{
return daoFactory;
}
public static void setDaoFactory(IDAOFactory daoFactory)
{
DAOHelper.daoFactory = daoFactory;
}
This now enables any class intance to get the DAO factory. What I want to know is - is this safe. If two threads call
DAOHelper.getDaoFactory()
at the same time what will happen? Should I synchronize the
DAOHelper.getDaoFactory()
mathod?
Thanks.