This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Question about Data class instances Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Question about Data class instances" Watch "Question about Data class instances" New topic
Author

Question about Data class instances

Efstathios Arethas
Greenhorn

Joined: Jun 07, 2009
Posts: 5
Hello guys!

I am almost done with the project , but i have some thoughts about the Data class , lets take this scenario the user starts a server , then the user starts also a standalone client to work with the same file as the server does , so both server and client work with same db file, i want the server and the standalone client to share the same Data object under the same VM , for the time being they don't share it , in my Data class i use lazy initialization like Map<DatabaseLocation,Data> so from the getInstance( DatabaseLocation) method i expect to get the same Data object , but i don't because the objects i get have different hash codes when i use the same db location string, why this happens? I have tried the singleton pattern also but still different hash codes! I just want to have one Data object per db file , in order the locking mechanism to work for all threads , i must say the server locks the records when requested by the net clients but works independently from the standalone client because they don't share the same Data object. Please advise.
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 4924
    
  10

From my instructions:
You may assume that at any moment, at most one program is accessing the database file; therefore your locking system only needs to be concerned with multiple concurrent clients of your server.

So your scenario will never occur


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Efstathios Arethas
Greenhorn

Joined: Jun 07, 2009
Posts: 5
Roel De Nijs wrote:From my instructions:
You may assume that at any moment, at most one program is accessing the database file; therefore your locking system only needs to be concerned with multiple concurrent clients of your server.

So your scenario will never occur


Hello Roel
You have right ! I missed this one!
Thank you
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question about Data class instances
 
Similar Threads
URLyBird - Database Access
Object identity
Data class and server code
does this sound good/okay/terrible?
Starting OCMJD