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 synchronized in local mode 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 "synchronized in local mode" Watch "synchronized in local mode" New topic
Author

synchronized in local mode

Garandi Garandi
Ranch Hand

Joined: Jan 07, 2003
Posts: 192
Data class is used to access data in Local mode, I am planning to remove all the synchronized key word from method heading in Data class, any comments ?
Thank you
Garandi
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937

Data class is used to access data in Local mode, I am planning to remove all the synchronized key word from method heading in Data class, any comments ?

I assume that in remote mode, your clients use a remote object that wraps the same instance of Data. If so, the methods of Data must be synchronized to insure thread safety.
Eugene.
Garandi Garandi
Ranch Hand

Joined: Jan 07, 2003
Posts: 192
Eugene,

I assume that in remote mode, your clients use a remote object that wraps the same instance of Data. If so, the methods of Data must be synchronized to insure thread safety.

Yes, that is what I do.
But what if I remove synchronized from Data and make all my RemotedataServer methods synchronized?
Eugene, I send you a private msg. could you please let me know about it.
Thank you
Garandi
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937

But what if I remove synchronized from Data and make all my RemotedataServer methods synchronized?

But each client has its own RemotedataServer object, right? If so, nothing will prevent client A to call a modify() method of Data while client B is in the middle of it. You need some sort of inter-client (as opposed to intra-client) synchronization, and the common solution here is that remote cients use their own remote objects, but all of these remote objects use the same instance of Data, whose methods are synchronized. This guaranties that although the clients are never aware of each other, they never collide, since there is a semaphore at the crossing, i.e. the synchronized methods of Data.
Eugene.
[ January 15, 2003: Message edited by: Eugene Kononov ]
Garandi Garandi
Ranch Hand

Joined: Jan 07, 2003
Posts: 192
Thank you it is clear now.
Garandi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: synchronized in local mode
 
Similar Threads
lock and unlock in local mode
lock unlock methods
Identifying the thread that placed the lock
Locking/Unlocking, -- Am I Done Or I Don't Understand Requirements?
not sure which methods must be synchronized