• 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

ExecutorService invokeAny Working

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I wanted to know the gaurantees the invokeAny method of ExecutorService gave!
The documentation says :

invokeAny
<T> T invokeAny(Collection<Callable<T>> tasks)
throws InterruptedException,
ExecutionException
Executes the given tasks, returning the result of one that has completed successfully (i.e., without throwing an exception), if any do.
Upon normal or exceptional return, tasks that have not completed are cancelled.



Take this scenario: I create 10 Callables. In Main thread , I call invokeAny on the list of these Callables. All of them start running.
At this point, The Main thread is blocked (right?). Now, one of the Callables complete.
Now at this particular point, what happens?
Because the Main thread was blocked, it goes into READY state and waits for the scheduler to make it RUNNING.
However, during this time, some other Callable might also lead to completion.
The other Callables will be cancelled only when the Main thread gets a chance to run next.

So my question:
Is it possible (like in above scenario) that more than one Callable may lead to completion.
Or the invokeAny method gaurantees that one and only Callable will lead to completion (This implies that the thread which will run after the first Callable has completed is the Main thread).

Any comments appreciated
Thanks
 
punit agrawal
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
any comments?
reply
    Bookmark Topic Watch Topic
  • New Topic