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
What is the difference between superclass and subclass?
What is a method in coding?
What is the use of arraylist class in java?
Is java free for commercial?
What is JFC?
What are memory tables?
Describe what happens when an object is created in java ?
What is string made of?
What are variable names?
What is garbage collection? What is the process that is responsible for doing that in java?
What are 3 data types?
What is palindrome in java?
Can we print null in java?
how to create constants in java?
What is a stack class in java ?