This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes Threads and Synchronization and the fly likes Create new Thread with FutureTask vs using Executor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Create new Thread with FutureTask vs using Executor" Watch "Create new Thread with FutureTask vs using Executor" New topic
Author

Create new Thread with FutureTask vs using Executor

Swerrgy Smith
Ranch Hand

Joined: Mar 26, 2010
Posts: 91
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

Joined: Jan 28, 2003
Posts: 4181
    
  21

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.


Steve
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: Create new Thread with FutureTask vs using Executor
 
It's not a secret anymore!