• Post Reply Bookmark Topic Watch Topic
  • New Topic

execute vs submit ( ThreadPoolExecutor)  RSS feed

 
Steven Rodeo
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Folks,

Sorry if this sound too basic... What is the difference between a submit and an execute of a Runnable task in a ThreadPoolExecutor.

A sample code fails with a RejectedExecutionException when we attempt to use execute ( Ofcourse Calling the shutdown on the ThreadPoolExecutor )

The same code 'Seems' to work with submit... Are we lucky ? or is it some race condition or a difference between execute and submit that eludes me ?

Thanks a bunch...
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey the only difference being that all the flavors of submit() returns a Future that can be used to query the result of the submitted task execution.
On the other hand, execute() does not return a Future.
There is no difference in the implementation and in fact submit() internally calls execute()!

Steven: A sample code fails with a RejectedExecutionException when we attempt to use execute ( Ofcourse Calling the shutdown on the ThreadPoolExecutor )


Are you saying that when you are calling execute() after shutdown, it throws a RejectedExecutionException but calling submit() does not?
I dont think it behaves like that. Can you post your sample code.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!