Why we use static and synchronized in method for single
thread model
example:
public static synchronized add(){}
Answers were Sorted based on User's Feedback
Answer / deepak verma
Synchronized static method means, the lock belongs to the
class, no other thread can access any static synchronized
method of this class when one thread already holds the lock
of that class.
This class lock is independent of locks on its object. For eg :
Class A {
public static synchronized add() {}
public synchronized void someMethod() {}
}
Here add() and someMethod() can be called concurrently as
add() is having class lock whereas someMethod() having
object lock.
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / sameer
Ststic means it belongs to class.When u call a syncronized
method u keep the luck of that class.
| Is This Answer Correct ? | 2 Yes | 4 No |
What is the range of the short type?
What is a qualifier in a sentence?
What is multiple inheritance & can we implement it in java?
What is diffrance between FINALIZE() & FINALLY ?
What is the use of http-tunneling in rmi?
What is the current version of java?
What are E and PI?
Difference between static synchronization vs. Instance synchronization?
What do you understand by an io stream?
What is OOP?
What is a percentage sign called?
when everything can be done by static block then why do we use main method?.