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 a class reference?
Write a java program to check if a number is prime or not?
What is the locale class in java programming?
What do you understand by java virtual machine?
How does compareto work in java?
Explain what is encapsulation?
How do I remove a character from a string in java?
What does || mean in vectors?
What is a method header?
Is object a data type?
Explain the differences between static and dynamic variables?
Why put method is idempotent?
What does a za z0 9 mean?
Which is better singleton or static class?
Where are the local variables stored?