• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

doubt regarding the ExecutorService future object

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have these code



the op of the following prog. is like that
start
end
futurefalse
futurefalse
shutdown
get the result
get the result0
get the result1
get the result2


But  i don't understand  why the future.isDone is printing the false as the future object is generating
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Aniket Harode wrote:
But  i don't understand  why the future.isDone is printing the false as the future object is generating



The isDone() method is returning false, because the task that the future object is representing has not completed yet. Not exactly sure of your confusion though.

Henry
 
Ranch Hand
Posts: 230
IntelliJ IDE Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you try using Future.get() to check if the task got completed ?
it is a blocking call and may block until the task gets completed.

Post that invoking future.isDone() may return TRUE. I guess


You can try calling get(..) with an extremely short timeout. If it returns a value, it was completed.
If you get a TimeoutException, it wasn't.
If you get any other of the possible exceptions, it was either cancelled, failed, or was interrupted

When you call Future.get() method, there is 4 possible outcomes:
You get the result value
You get CancellationException - if the computation was cancelled (e.g. Future.cancel(true) is called)
You get ExecutionException - if the computation threw an exception
You get InterruptedException - if the current thread was interrupted while waiting (e.g. executor.shutdownNow() is called)
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic