• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

use the singleton server

 
Ying Ren
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am just thinking using singleton pattern in server. But I can not figure out how to deal with the constructor problem.
the code:
public class SingletonServer {
private static final SingletonServer instance= new SingletonServer(//I want to add the String variable);
.......
private SingletonServer (String s) {
}
How to initialize the instance?
And if we don't use the Singleton, is there any method to make the server thread safe, or just leave to the RMI itself to deal with it?
Thanks
Ying Ren
 
Sai Prasad
Ranch Hand
Posts: 560
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess you are talking about the server side Factory which extends UnicastRemoteObject and is responsible to create the remote Data objects. There is no need to make this server factory aka ConnectionFactory a Singleton. When you extend the UnicastRemoteObject, you are creating one instance(Uni) and bind to the RMI Registry. RMI takes care of creating multiple threads to access this Factory.
You need to make the server side classes threadsafe. RMI doesn't do this for you. Since the method to return the Connection object in the Factory is one line of code, you don't need to synchronize this one!
 
Ying Ren
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sai,
Thank you for your reply.
My server refer to the class which create the remoteDataAccess,and has registerToRegistry method.
In my program, the factory class just returns the DataInterface according to the different state: local or remote. If the state is remote, there is a Naming.lookup function. Is it right?
Do I need to singleton the server class?
Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic