Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

FutureTask  run() method

Posted on 2012-03-18
4
Medium Priority
?
366 Views
Last Modified: 2012-03-24
hi guys

From API

FutureTask.run()
          Sets this Future to the result of its computation unless it has been cancelled.

Can anyone give a simple example of what this means?

thanks
0
Comment
Question by:royjayd
  • 2
4 Comments
 
LVL 47

Expert Comment

by:for_yan
ID: 37736318
This is a simple example of the code showing how FutureTask is working:

http://programmingexamples.wikidot.com/futuretask

click on showcosde:
Example of FutureTask
+ Show Code  <--- click here

IThe code is reallytransparent and in compliance with the words in API.
0
 

Author Comment

by:royjayd
ID: 37736351
Thanks!
The link doesnt answer my question. I want to know what run() does with a simple example.
0
 
LVL 36

Accepted Solution

by:
mccarl earned 1400 total points
ID: 37736357
I agree the words in the Javadoc for that method are quite hard to understand without deeply understanding what is happening.

However, I can't really give an example of that method because user code would never call that method. That method is there so that when you call execute() method on some ExecutorService (as an example) with this FutureTask as the argument, the internals of the execute() call is actually what calls the FutureTask's run() method for you.

What FutureTask's run() method would do, is it would call either the run() method or the call() method of the Runnable/Callable that is passed in to FutureTask as the constructor argument.
0
 
LVL 47

Assisted Solution

by:for_yan
for_yan earned 600 total points
ID: 37736368
You'll not call this method yourself, that's what it says in the API:
This method is invoked internally by the run method upon successful completion of the computation.

ANd the way you use FuturTask that example shows very convincingly
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question