Why we use static and synchronized in method for single
thread model
example:
public static synchronized add(){}
Answer Posted / 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 |
Post New Answer View All Answers
Compare java and python.
Why is string buffer better than string ?
Define an enumeration?
How to change value in arraylist java?
What are the 3 types of loops in java?
Write an algorithm for quick sort?
What is flag in java?
Explain about main thread in java?
How to do encapsulation in java?
Why can't we use static class instead of singleton?
What are some characteristics of interference class?
Explain about data types?
What is the use of flag?
How destructors are defined in java?
What is a nonetype?