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

Explain restrictions for using anonymous inner classes?

0 Answers  


What type of language is java?

0 Answers  


How can you make a class serializable in java?

0 Answers  


Which is the best approach for creating thread ?

0 Answers  


. Explain Java String Pool.

1 Answers  


What are assembly attributes?

0 Answers  


why Interface used?

0 Answers   HCL,


What is the default access specifier for variables and methods of a class?

0 Answers  


what is use of session tracking ?with example?

1 Answers   Photon,


What is the importance of finally block in exception handling?

0 Answers  


What are variable names?

0 Answers  


In what type of containers, Border layout is a default layout?

3 Answers  


Categories