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
Is int primitive data type?
What is use of inner class in java?
What is the access scope of protected access specifier?
What is a package in java? List down various advantages of packages.
What is an example of a keyword?
What is the this keyword?
What is continuity of a function?
How does sublist works in java?
How to create a thread in java?
What is the difference between dom and sax parser in java?
Does constructor be static?
What is the multi-catch block in java?
Can we override private method in java?
Can finally block be used without a catch?
Which is better stringbuilder or stringbuffer?