File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Synchronized Static Method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Synchronized Static Method" Watch "Synchronized Static Method" New topic

Synchronized Static Method

Sun LiWei
Ranch Hand

Joined: Aug 10, 2002
Posts: 49
I am confused by synchronized on static method,just like this:

My question is:
Does the object pool synchronize???
In my mind,synchronized on method

is the same as

But in static method,the keyword "this" is not allowed.So,what exactly "synchronized static method()" mean???
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
When you synchronize on a static method you are placing a lock on the class for the duration of the static method.

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Santosh Terkhedkar

Joined: Mar 18, 2001
Posts: 2
Visit this link
read critical section in java Threads.
I think this will certainly help you solve your problem.
Santosh Terkhedkar.
Valentin Crettaz
Gold Digger

Joined: Aug 26, 2001
Posts: 7610
synchronizing a static method locks on the java.lang.Class object representing the class, for instance in:

is the same as

[Blog] [Blogroll] [My Reviews] My Linked In
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
When a class or interface is loaded a java.lang.Class instance is created to represent it. You can access references to them via the Class literals

SCJP2. Please Indent your code using UBB Code
I agree. Here's the link:
subject: Synchronized Static Method
It's not a secret anymore!