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



Why we use static and synchronized in method for single thread model example: public static syn..

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

Why we use static and synchronized in method for single thread model example: public static syn..

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

Post New Answer

More Core Java Interview Questions

What is treemap in java?

0 Answers  


What is the advantage of functional interface in java 8?

0 Answers  


What is the size of boolean variable?

0 Answers  


What is method overloading with type promotion?

0 Answers  


Can a class have more than one object?

0 Answers  






What is string builder in java?

0 Answers  


How to convert string to byte array and vice versa?

0 Answers  


What does exclamation mean in java?

0 Answers  


What is the difference between jfc & wfc?

0 Answers  


what is the purpose of the runtime class?

0 Answers  


Can an interface have a constructor?

0 Answers  


Can we override constructor?

0 Answers  


Categories