This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes explanation needed Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "explanation needed" Watch "explanation needed" New topic
Author

explanation needed

krish bajaj
Ranch Hand

Joined: Jun 19, 2006
Posts: 31
what is the concept of class specific locks
help by giving any example

thanks
Naseem Khan
Ranch Hand

Joined: Apr 25, 2005
Posts: 809
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


Asking Smart Questions FAQ - How To Put Your Code In Code Tags
S Thiyanesh
Ranch Hand

Joined: Mar 19, 2006
Posts: 142
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

Joined: Jun 19, 2006
Posts: 31
thanks Nassem
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: explanation needed