my dog learned polymorphism*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Static and Non static Synchronized methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Static and Non static Synchronized methods" Watch "Static and Non static Synchronized methods" New topic
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Static and Non static Synchronized methods
 
Similar Threads
static and non static
Synchronization
Class level syncronization v/s Method level Syncronization
Methods
synchronized blocks for static and non-static methods