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 |
Why to use nested classes in java? (Or) what is the purpose of nested class in java?
Why is prepared Statement, Callable Statement used for? What is the need of Batch updates?
Explain list interface?
What are the two environment variables that must be set in order to run any java programs?
What is JDBC Driver interface?How can you retrieve data from the ResultSet
What does null mean in java?
What is locale in java?
What is type conversion in java?
How do you declare an array in java?
What is variable declaration and definition?
How many bits is a float?
Can we override a variable in java?