| Author |
Static and Non static Synchronized methods
|
Kishore Kumar
Ranch Hand
Joined: Oct 15, 2007
Posts: 71
|
|
Hi, CAn any one let me know, Is there any difference between static and non-static synchronized methods? If yes, what is the difference?
|
 |
abhishek pendkay
Ranch Hand
Joined: Jan 01, 2007
Posts: 184
|
|
|
yes static synchronized methods lock on the class and instance methods lock on the object
|
The significant problems we face cannot be solved by the same level of thinking which created them – Einstein
SCJP 1.5, SCWCD, SCBCD in the making
|
 |
Kishore Kumar
Ranch Hand
Joined: Oct 15, 2007
Posts: 71
|
|
|
Thanks for your reply. Then suppose there are 2 threads. Thread-1 is accessing static synchronizes method. Now can thread-2 access non-static synchronized method if thread-1 is accessing staic synchronized method.
|
 |
abhishek pendkay
Ranch Hand
Joined: Jan 01, 2007
Posts: 184
|
|
|
yes if Thread-1 is accessing static synchronized methods of a class then Thread-2 can access the non-static synchronized methods of that class... the point is static synchronized methods and non-static synchronized methods dont block each other
|
 |
Kelvin Chenhao Lim
Ranch Hand
Joined: Oct 20, 2007
Posts: 513
|
|
Another way of looking at it is that the "synchronized" modifier is essentially just syntactic sugar for these two constructs: "static synchronized void foo()" is behaviorally equivalent to: "synchronized void foo()" is behaviorally equivalent to: [ November 05, 2007: Message edited by: Kelvin Lim ]
|
SCJP 5.0
|
 |
 |
|
|
subject: Static and Non static Synchronized methods
|
|
|