Monday, March 2, 2015

About Thread blocking

1)
Thread calling non-static synchronized method block each other when they works on the same instance of the respective class.
when they works on different object of the class then they do not block each other.

2)
Thread calling static synchronized method block each other because they work on the class level not on the instance level. because it is 
static synchronized method it is common among all the instances of the class.

3)
Thread calling static synchronized method and non-static synchronized method do not block each other because both are different level method.
static method is the class level method which is common for all instances and non-static method work as per instance of the class.

4)
In case of the synchronized block thread block each other if they works on the same object. Thread working on
different object will not effect each other they won't block each other.

Care:
Access to non-static fields should be done from the non-static synchronized method and
access to static fields should be done from the static synchronized methods

No comments:

Post a Comment

Scrum and Scrum master

Scrum  Scrum is a framework which helps a team to work together.  It is like a rugby team (the scrum name comes from rugby game). Scrum enco...