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 an interface in java?
Define how can we find the actual size of an object on the heap?
What are different type of exceptions in java?
What is this keyword in java?
What is final keyword?
What is static variable with example?
What if I write static public void instead of public static void in java?
Is vector ordered in java?
What is multi-catch block in java?
What is return type in java?
Hi.... I applied for the post of scientific officer/Engineer-SB(Programmer).Please post the syllabus and sample papers.
Can we declare a class as static?
What are different types of inner classes ?
Explain hashset and its features?
What class of exceptions are generated by the java run-time system?