Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

explanation needed

 
krish bajaj
Ranch Hand
Posts: 31
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is the concept of class specific locks
help by giving any example

thanks
 
Naseem Khan
Ranch Hand
Posts: 809
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When a thread accesses a static synchronized method of a class, then it acquires the class lock i.e., Test.class lock instead of Test's instance lock.

It will be better understood by this code....



Here you will get only one output. either main or child.


Naseem
 
S Thiyanesh
Ranch Hand
Posts: 142
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class specific locks can be acquired by
1.synchronizing on static methods.
2.synchronizing on the static objects defined in the class.
3.Locking on external objects like System.out
4.Locking on Singleton Objects.
 
krish bajaj
Ranch Hand
Posts: 31
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Nassem
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic