Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

singleton

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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;
}


}
 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You assumption is right, every JVM will have its own instance of singleton.
 
Raj Joe
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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)
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic