• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

synchonized method

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic