This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes synchonized method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "synchonized method" Watch "synchonized method" New topic

synchonized method

Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
From Khalid book: pg no.282
WHich of the following statements are true?
a) No two threads can ever simultaneously execute synchonized method on the same object.
b) Method declared synchonized should not be recursive
c) synchonized methods can only call other synchonized methods directly.
d) Inside synchonized methods one can be assume that no other threads are currenly executing a method in the same class.
My answere a) and d)
But given answere is just a)
Please can anybody explain?
Uvnik Gupta
Ranch Hand

Joined: Jul 24, 2000
Posts: 32
A class may have synchronized as well as non-synchronized methods. If a thread is executing a synchronized method then that thread has locks on the objects SYNCHRONIZED methods and blocks. So another thread can simultaneously execute any of the NON-SYNCHRONIZED methods of the same object. Hence option #4 is wrong.
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944

My understanding of option d) was, when a thread is executing a synchronised method, it is rest asured that no other thread is currently executing that synchronized method at the same point of time. So my answere was true. Or does is it something else. Mean while like you mentioned other threads can execute non-synchronized method. Am I right? Please clarify.
I agree. Here's the link:
subject: synchonized method