• Post Reply Bookmark Topic Watch Topic
  • New Topic

What is the diff btw these ?

 
Hussein Baghdadi
clojure forum advocate
Bartender
Posts: 3479
Clojure Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey folks.
what is the diff btw :

and

thanks
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Synchronization always involves a "lock" or "monitor" object. While one synchronized block of code is holding the lock for a particular object, no other synchronized block (or method) can obtain that same lock, and so has to wait. Different locks are completely independent.

The difference here is that the first one uses the current object -- i,e., the object in whose class definition the "synchronized" block appears -- as the lock. The second one uses "object" as the lock. Either can be correct in a particular context; you have to understand how synchronization is being used in that particular case to decide between them.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!