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

A question on inner class  RSS feed

 
Chaobai Huang
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are two inner class extending TimerTask inside the same class. One run every 2 minutes and another 4 minutes. How can I let only one run() method executing at the same time and every run() method sould be atomic? Is it enough to add a big sychronized(OuterClass.this) inside each run() method?
Please help. Wait online.
 
Chaobai Huang
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One more question. I want use wait() in one run() and notify() it in another run(). but failed. How can I write the code?
Because the task is urgent. Please give me some help. Thanks all. ^-^
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alternatively, you create a dedicated lock object in Foo; it depends on how synchronization on Foo itself must interact with task synchronization.Finally, it may in some cases be cleaner to pull all the code into Foo itself:Hope this helps,
- Peter
[ October 15, 2003: Message edited by: Peter den Haan ]
 
Chaobai Huang
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot, Peter! It really helps me.^-^
 
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!