Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Static Synchronized methods

 
lakshmi v.samy
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody
I have one situation like this,two different threads are there.they are going to execute two different static sychronized methods.my questions if one thread is executing one static synchronized method whether other method will be blocked otherwise both will be executed simultaneously.
please guide me.
Thanks in advance
 
Henry Wong
author
Marshal
Pie
Posts: 21202
81
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by lakshmi v.samy:
Hi everybody
I have one situation like this,two different threads are there.they are going to execute two different static sychronized methods.my questions if one thread is executing one static synchronized method whether other method will be blocked otherwise both will be executed simultaneously.
please guide me.
Thanks in advance


If one thread is executing a static synchronized method, all other threads trying to execute any static synchonized method, in the same class, will block.

Henry
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's useful to realize that the syntax for synchronized methods and static synchronized methods is just syntactic sugar, and that you can use synchronized blocks in their place:

It's not clear whether the original poster was thinking of static methods in the same class or across classes, but if you use the more explicit synchronized block syntax, you can have it as you like.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic