Problem with singleton helper class for java rmi server.

  • Thread starter Arijit Mukherjee
  • Start date
A

Arijit Mukherjee

Hi,

I have created a single rmi server - which has registered with a JNDI
compliant naming service. The server uses services of singleton helper
classes. I had expected that the private constructors of these helper
classes (which are called from their own static block) would get executed
only when I create the instance of the server - which I register with the
naming service. Instead, for every client JVM launched, the private
constructors of these singleton classes get executed. I am not sure why. The
following pseudo code explains the scenario:
class serverItf extends remote
{
// The exposed methods
public HashMap a() throws RemoteException;
}



class serverImpl extends unicastRemoteObject implements serverItf
{
public HashMap a() throws RemoteException
{
return (SingletonHelper.getInstance()).a();
}
}



class serverLauncher
{
public static void main(String args[])
{
// Registers an instance of serverImpl with
// naming service
}
}



class SingletonHelper
{
static SingletonHelper myself;
static {
myself = new SingletonHelper();
}

private SingletonHelper()
{
System.err.println("Constructor of " +
" SingletonHelper called");
}

private static SingletonHelper getInstance()
{
return myself;
}

public HashMap a()
{
// Business Logic of a
}
}
When I launch multiple instances of clients in multiple JVMs - the
constructor of SingletonHelper is called - for both. However, if I call
multiple remote methods from the same client instances - the constructor
gets executed only once. Any help is highly appreciated,

Thanks and regards, Arijit
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top