• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

submit(Callable<T> task) method in ThreadPoolExecutor class

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ThreadPoolExecutor inherits submit(Callable<T> task) method.
The constructor of ThreadPoolExecutor accepts an instance BlockingQueue<Runnable>. This blocking queue can hold Runnable instances only.
Javadoc for ThreadPoolExecutor constructor says:
"the queue to use for holding tasks before they are executed. This queue will hold only the Runnable tasks submitted by the execute method."
Question : How tasks submitted through submit(Callable<T> task) are queued?
 
author
Posts: 23883
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Anuj Singhal wrote:
Question : How tasks submitted through submit(Callable<T> task) are queued?



Before we provide you the answer, would you like to take a guess first?

Henry
 
Anuj Singhal
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seems, I am missing a very simple and basic concept.
I guess the same queue would be used.
 
Henry Wong
author
Posts: 23883
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Anuj Singhal wrote:Seems, I am missing a very simple and basic concept.
I guess the same queue would be used.



Well, obviously, the queue would be used. As for how it would be used ... hint ... question ... how would you put a primitive int into an arraylist that takes Integer objects? If you can answer this, then you should be able to figure out how to put a Callable objects into a queue that takes Runnable objects.

Henry
 
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


how would you put a primitive int into an arraylist that takes Integer objects? If you can answer this, then you should be able to figure out how to put a Callable objects into a queue that takes Runnable objects.



Hi Henry ,
are you trying to say when pass Callable to submit() it implicitly convert this to Runnable ?

Am trying some thing like :



Here the Callable will convert to Runnable ?

Thanks ,
Satya
 
Henry Wong
author
Posts: 23883
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

S Majumder wrote:
are you trying to say when pass Callable to submit() it implicitly convert this to Runnable ?

...


Here the Callable will convert to Runnable ?



Of course, this is implementation detail, so, it may be different with different versions of the JVM. It may be also different in the future.

To answer your question, a wrapper class is used. The wrapper is of type Runnable (and also type Future), and it HAS-A instance of Callable.

Henry
 
S Majumder
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Henry , detail descriptions will be appreciable ..

Satya
 
reply
    Bookmark Topic Watch Topic
  • New Topic