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
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