Solved

FutureTask  run() method

Posted on 2012-03-18
4
358 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Suggested Solutions

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

710 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