• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Synchronized Static Method

 
Sun LiWei
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you synchronize on a static method you are placing a lock on the class for the duration of the static method.
-Barry
 
Santosh Terkhedkar
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Visit this link
http://www.javaworld.com/javaworld/jw-04-1999/jw-04-toolbox.html
read critical section in java Threads.
I think this will certainly help you solve your problem.
Cheers,
Santosh Terkhedkar.
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
synchronizing a static method locks on the java.lang.Class object representing the class, for instance in:

is the same as
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic