File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

confusion about object lock.

 
pawan chopra
Ranch Hand
Posts: 415
jQuery Mac Objective C
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I have a class as shown below:



this class has two methods they are synchronized. Now let us say thread 1 is executing firstMethod while its executing that thread 2 tries to execute the second method on same object. Will it be able to execute it or not? If yes then how come this is lock on a object? I hopw this is not a silly question. Please help.
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When a synchronized method of an object is called, all other synchronized of the same object will block until the executed method ends.
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is an example where the first method sleeps 5 seconds. Check what happens with and without the synchronized keyword on the second method.
 
pawan chopra
Ranch Hand
Posts: 415
jQuery Mac Objective C
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Christophe!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic