File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes creating new Data Object for each client Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "creating new Data Object for each client" Watch "creating new Data Object for each client" New topic
Author

creating new Data Object for each client

Yassine Lajmi
Greenhorn

Joined: Oct 11, 2002
Posts: 9
Hi all,
I have a question concerning the rmi server :
do i have to create a new Data instance for each client or a single instance of data is Ok.
if yes how to do it.
thanks


SCJP<br />SCJD<br />SCBCD<br />SCWCD<br />OCA 9i
Manish Kumar
Ranch Hand

Joined: Apr 15, 2002
Posts: 53
Hi Lajmi,
I think that creating a new Data object for each client would definitely corrupt your db.db file. You shouldn't create more than one instance of the Data class.
with regards,
Manish Kumar
Yassine Lajmi
Greenhorn

Joined: Oct 11, 2002
Posts: 9
thank you Kumar,
In this case how to be sure that a single instance of data was created for each client.
I have made a simple System.out.println in the constractor of Data, and for each Client it is printed.
i don't understend why a new instance is created.
in the server :
try{
Registry r = LocateRegistry.createRegistry(port);
database = new DataAccessImpl(dbFileName);
r.rebind(bindName, database);
}catch(Exception e){
System.out.println("Exception occurred on DataServer : " + e);
System.exit(0);
}
in the Client side :
System.setSecurityManager(new RMISecurityManager());
dataAccess = (DataAccess) Naming.lookup("rmi://"+serverDNS+":"+port+"/DataAcess_BindName");
Manish Kumar
Ranch Hand

Joined: Apr 15, 2002
Posts: 53
u should use the factory pattern.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: creating new Data Object for each client