Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Static Synchronized methods  RSS feed

 
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
 
author
Sheriff
Posts: 23507
138
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
 
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.
 
Beware the other head of science - it bites! Nibble on this message:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!