It's not a secret anymore!*
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 Android Security Essentials Live Lessons this week in the Android 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: 88
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: 4167
    
  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
 
Consider Paul's rocket mass heater.
 
subject: Create new Thread with FutureTask vs using Executor
 
Similar Threads
use of FutureTask
how to generate thread in web application
Using FutureTask with Tomcat's thread pool
Thread question
Catching exception from a Thread