Why we use static and synchronized in method for single
thread model
example:
public static synchronized add(){}
Answers were Sorted based on User's Feedback
Answer / 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 |
Answer / sameer
Ststic means it belongs to class.When u call a syncronized
method u keep the luck of that class.
| Is This Answer Correct ? | 2 Yes | 4 No |
Which api is provided by java for operations on set of objects?
who was the founder of java
32 Answers CTS, HCL, ProKarma,
What is meant by class loader and how many types are there?
What is the difference between actual and formal parameters?
java Technical questions asked by JPMC
Is 0 a real number?
What is toarray method in java?
Can I learn java in 3 months?
Why is the main method static?
Which types of exceptions are caught at compile time?
What about anonymous inner classes in java?
Are global variables initialized to zero?