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 assembly language?

0 Answers  


Does java allow default arguments?

0 Answers  


What is meant by binding in rmi?

0 Answers  


Is array a class in java?

0 Answers  


What is listnode in java?

0 Answers  






where do we use init()

2 Answers  


What is Exception handling in Java How do you handle run time errors please explain with an example

2 Answers   Mastek, TCS,


How 'java' got its name and what it stands for?

11 Answers   Wipro,


class test { private static void main(String []adsf) { } } explain me that the above code is error or exception

3 Answers  


What are variable arguments or varargs?

0 Answers  


Can an unreachable object become reachable again?

3 Answers   DELL,


What is the difference between == and === javascript?

0 Answers  


Categories