• Post Reply Bookmark Topic Watch Topic
  • New Topic

synchronized on deserialized variables  RSS feed

 
Denis Wen
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!