Thanks.
Here is the code for my factory:
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import javax.ejb.EJBHome;
import javax.ejb.EJBLocalHome;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;
public class EJBHomeFactory
{
private Map ejbHomes;
private static EJBHomeFactory aFactorySingleton;
InitialContext ctx;
/**
* EJB home factory private constructor
*/
private EJBHomeFactory() throws NamingException
{
ctx = new InitialContext();
this.ejbHomes = Collections.synchronizedMap(new HashMap());
}
/*
* Returns the singleton instance of EJBHomeFactory
*/
public static EJBHomeFactory getFactory()
{
try
{
if(EJBHomeFactory.aFactorySingleton == null)
{
EJBHomeFactory.aFactorySingleton = new EJBHomeFactory();
}
}catch(Exception e)
{
System.out.println("exception in static ejb home factory "+e);
}
return EJBHomeFactory.aFactorySingleton;
}
/**
* Look up and cache an EJBHome object using a home class.
*/
public EJBHome lookUpHome(Class homeClass)
{
EJBHome anEJBHome;
anEJBHome = (EJBHome)this.ejbHomes.get(homeClass);
try
{
if(anEJBHome == null)
{
anEJBHome = (EJBHome)PortableRemoteObject.narrow(ctx.lookup(homeClass.getName()), homeClass);
this.ejbHomes.put(homeClass, anEJBHome);
}
}catch(Exception e)
{
System.out.println("exception in look up home "+e);
}
return anEJBHome;
}
}
I am not sure whether the object of this class will get garbage collected if no other class in the system is referring to it.
Can you help me out with this?