This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach 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 Murach's Java Servlets and JSP this week in the Servlets 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: 4165
    
  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
 
wood burning stoves
 
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