Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

synchronization, lock/unlock

 
Rasika Chitnis
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the source code supplied by Sun, method writeRecord is a private non-synchronized method. This method is called by add and modify, both these are public synchronized methods. My understanding is, when a synchronized method calls a non-synchronized method, the object that owns the synchronized method is still locked while non-synchronized method is being executed. If this is true, then why do we need lock, unlock methods ? In fact, I think, the only methods that need to be synchronized are seek and writeRecord, because this is where the shared data is manipulated.
My second question is, when one thread is executing a synchronized method, can other threads concurrently execute other non-synhronized methods ?
Your answer is very much appreciated. Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic