Solved

FutureTask  run() method

Posted on 2012-03-18
4
342 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 35

Accepted Solution

by:
mccarl earned 350 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 150 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

911 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now