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

Future task is done or not ?  RSS feed

 
Edward Chen
Ranch Hand
Posts: 798
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the Future, does the main thread need to wait for the future job ?

for example

in the Line A, why we not need to make sure if the thread job is done ? something like



Then next question is , how could we implement this: if p, q thread is not done in 10s, main thread will throw exception and terminate the logic.

Thanks
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The get() method in Future is defined to block until the task has completed, or until an exception is thrown. So this is already taken care of for you. There's no need to implement waiting.
[ January 20, 2008: Message edited by: Jim Yingst ]
 
vu lee
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Jim stated, get() method will block the current thread till the task is done. You could call the overloaded method get(10,TimeUnit.SECONDS) which would block about 10 seconds then throw Timeout Exception if it the task has not been completed.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!