aspose file tools*
The moose likes Websphere and the fly likes singleton Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Products » Websphere
Bookmark "singleton " Watch "singleton " New topic
Author

singleton

Raj Joe
Ranch Hand

Joined: Oct 15, 2004
Posts: 41
What happens to singletons in websphere clustered envorinment.I assume that for every JVM in the cluster we will have a singleton.

In the below code what happens to cachedReferences in a websphere clustered environment

public class ServiceLocator
{
private static ServiceLocator serviceLocator;

/**
* The initial context object
*/
private InitialContext initCtx;

/**
* The Map object representing the Cached info
*/
private Map cachedReferences;



/**
* The private Constructor
*/
private ServiceLocator()
{
cachedReferences = new HashMap(10);
try
{
initCtx = new InitialContext();
}
catch (NamingException ne)
{
}
}

/**
*
* Method getInstance to get back static instance of Service Locator
*
* @return Singleton instance of Service Locator
*/
public static ServiceLocator getInstance()
{
if (serviceLocator == null)
{
serviceLocator = new ServiceLocator();
}
return serviceLocator;
}

public EJBLocalHome getLocalHome(String jndiName, Class homeInterfaceClass)

{
EJBLocalHome ejbHome = null;

Object object = cachedReferences.get(jndiName);

if (object == null)
{
try
{
object = initCtx.lookup(jndiName);
cachedReferences.put(jndiName, object);
}
catch (NamingException ne)
{
}
}


ejbHome = (EJBLocalHome ) PortableRemoteObject.narrow (object,homeInterfaceClass);


return ejbHome;
}


}
Arvind Shukla
Ranch Hand

Joined: Jun 26, 2002
Posts: 38
You assumption is right, every JVM will have its own instance of singleton.


Arvind,<br />IBM Certified WAS admin (Test 489, Test 340, Test341)
Raj Joe
Ranch Hand

Joined: Oct 15, 2004
Posts: 41
Originally posted by Arvind Shukla:
You assumption is right, every JVM will have its own instance of singleton.


Arvind
Can I create a global reference(same static variable or singleton) for all JVMs in the cluster.

Is there any issue with caching remote or local home objects in a singleton as I described earlier.(As they are going to be repaeated in cache of each JVM in cluster)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: singleton
 
Similar Threads
Providing sessionbeans through init()
Service Locator
ServiceLocator with stateful session beans EJB 3.0
must the service locator be a singleton
static code?