This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Java in General and the fly likes synchronized Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "synchronized" Watch "synchronized" New topic
Author

synchronized

Chinmay Bajikar
Ranch Hand

Joined: Dec 08, 2001
Posts: 159
Hi,
Would I have a class level lock if I write a synchronized block for a static member of the class rather than an object level lock that I would get when I put "synchronized" in the method signature.
Thanks,
Chinmay


The strength of the Wolf is the pack & the strength of the pack is the wolf....Rudyard Kipling
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24168
    
  30

Yes. In Java, for every loaded class in the JVM, there's an instance of java.lang.Class that represents that class. Synchronized static methods use the class's java.lang.Class object as a lock.


[Jess in Action][AskingGoodQuestions]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: synchronized
 
Similar Threads
Synchoronization at class level
Deadlock
Class Wide Lock..??
synchronized
static synchronized method?