Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Can any explain me its flow please  RSS feed

 
Ajay Jaiswal
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



Hi All,

Given above code compile successfully, but when i try to run this code its hang and doesnt do any thing.

Regards,
Ajay Jaiswal

[ UD: added CODE tags for better readability ]
[ September 25, 2007: Message edited by: Ulf Dittmer ]
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It most certainly does something. Thread "t" enters the synchronized block, prints something, and then waits for a notification. That notification will never come, though, because there is no code sending one.

Note that "this" refers to two different objects in the two threads. So calling this.notify() in t2 has no effect on this.wait() in t.

Actually, even if "this" were the same object in both threads, it still wouldn't work, because then both threads would synchronize on the same object, and one of them would not be able to enter the synchronized block.
 
Vlado Zajac
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ulf Dittmer:

Actually, even if "this" were the same object in both threads, it still wouldn't work, because then both threads would synchronize on the same object, and one of them would not be able to enter the synchronized block.


No, because wait() releases the object lock.
[ September 25, 2007: Message edited by: Vlado Zajac ]
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
D'oh! You're right of course. Going to get more coffee right now...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!