• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Create new Thread with FutureTask vs using Executor

 
Swerrgy Smith
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I know that we can execute a FutureTask by calling:



However, if we create a new Thread with FutureTask in the classical way (because FutureTask also implements Runnable), what will be the difference?



In any case, we can still call to get the execution result.

Thanks.
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The difference is the executor will use a Thread pool to execute the task, re-using threads when possible. Also, depending on which executor you use, you could get a Queue with multiple Futures returned in the order of completion.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic