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

Does substring start with 0?

0 Answers  


What is difference between identifier and variable?

0 Answers  


How can you make a class serializable in java?

0 Answers  


How can constructor chaining be done using this keyword?

0 Answers  


What is the constructor?

0 Answers  






What are the parts of a method?

0 Answers  


class A { private int i; } class B extends A { private int i; } if I create an object of B class what will be the memory of that object.

2 Answers   Yamaha,


What is google full form?

0 Answers  


Which is not Object in Java?

10 Answers   Honeywell,


What is java command?

0 Answers  


How to display arraylist values in java?

0 Answers  


How do you find the absolute value?

0 Answers  


Categories