aspose file tools
The moose likes Threads and Synchronization and the fly likes synchronized on deserialized variables Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "synchronized on deserialized variables" Watch "synchronized on deserialized variables" New topic
Author

synchronized on deserialized variables

Denis Wen
Ranch Hand

Joined: Nov 11, 2008
Posts: 33
His,

I realize that my explanation is pretty vague, but along the code snippet it should clear up the question.

There is this method that we use to synchronize access to a map by its key. The key comes from deserializing argument from a remote call of a gwt client. In code:


The thinking behind this is that first you create an object to synchronize a block with intensive processing on. This object is a value of a map to guarantee proper synchronization to guarantee that if two requests with equal but not identical objectToSynchronizeOn come then one of them has wait before the second synchronized block is finished. I am not sure how synchronized keyword operates - does it only stop concurrent thread flow if it wants to obtain lock on the same object (which in case of deserialized requests is not true) or is the fact that two object are equal suffices.

The question is, if i can synchronized on a deserialized object directly without using intermediary map.

Thanks.
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 3041
    
    4

To synchronize between threads, you need to synchronize on identical Objects, not just equal Objects. So you will need some sort of Caching mechanism to make sure that you translate equality to identity - so yes you do need that sMap to do what it is doing...


Steve
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: synchronized on deserialized variables
 
Similar Threads
B&S, Q: good synchronization?
synchronized
isLock(int):boolean method and the synchronized block
Data Locking with a DB File.
NX: Does HashMap.containsKey(key) lock on the collection?