• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Anuj Singhal
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?
 
Henry Wong
author
Sheriff
Posts: 22853
119
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor 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
Sheriff
Posts: 22853
119
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor 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
 
S Majumder
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
Sheriff
Posts: 22853
119
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!