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

How do you invoke a method?

0 Answers  


How to make class immutable

6 Answers  


What are the properties of thread?

0 Answers  


What is a programming object?

0 Answers  


What is the difference between abstraction and encapsulation?

0 Answers  


What is the use of anonymous inner classes ?

12 Answers   DELL, HCL,


What are parameters in a method?

0 Answers  


What are invisible components?.

0 Answers  


What modifiers can be used with a local inner class?

2 Answers  


What is static and final keyword in java?

0 Answers  


What do you understand by a Static Variable?

0 Answers   CGI,


which one is performance wise advantageious from List,Set,Map?

6 Answers  


Categories