Questions tagged [futuretask]

A cancellable asynchronous computation. This class provides a base implementation of Future, with methods to start and cancel a computation, query to see if the computation is complete, and retrieve the result of the computation.

A cancelable asynchronous computation. This class provides a base implementation of Future, with methods to start and cancel a computation, query to see if the computation is complete, and retrieve the result of the computation. The result can only be retrieved when the computation has completed; the get method will block if the computation has not yet completed. Once the computation has completed, the computation cannot be restarted or cancelled.

A FutureTask can be used to wrap a Callable or Runnable object. Because FutureTask implements Runnable, a FutureTask can be submitted to an Executor for execution.

In addition to serving as a standalone class, this class provides protected functionality that may be useful when creating customized task classes. source.

208 questions
1
vote
2 answers

In Java FutureTask if the task Times out, does the Task get Cancelled?

Assuming I have the following code snippet: FutureTask f = new FutureTask<>(() -> { Thread.sleep(5000); return 1 + 2; }) myExecutor.execute(f); f.get(3, TimeUnit.SECONDS); From what is coded, the last line will fail after 3 seconds with…
1
vote
0 answers

Exception in callback of async function: Error: Future resolved more than once

Hi guys I try to use proxy-verifier NPM package in Meteor like below: import ProxyVerifier from 'proxy-verifier'; // this is my method call on server startup Jobs.find().forEach((job) => { Meteor.call("checkProxy", job.proxy, (error, result) => { …
b24
  • 2,425
  • 6
  • 30
  • 51
1
vote
1 answer

how to get results of Completeablefuture

In the Main class i am trying to run tasks asynchronously using CompletableFuture. and as shown in the code of FMSMsgHandlerSupplier class, it returns data of type Double[] the problem is, in the for-loop of the Main class the FMSMsgHandlerSupplier…
Amrmsmb
  • 1
  • 27
  • 104
  • 226
1
vote
2 answers

ThreadPoolExecutor check if certain Task is in queue

I have a serial connection which shall only be used by a single thread. But before I submit a new Task to the executors I want check if that certain Task is already in the queu(e.g for polling values). executor = (ThreadPoolExecutor)…
user2071938
  • 2,055
  • 6
  • 28
  • 60
1
vote
1 answer

how the function FutureTask.awaitdone() works?

recently,I read the source code about Java concurrent Jar,the code in FutureTask class is very hard to understand,the awaitDone method like this: private int awaitDone(boolean timed, long nanos) throws InterruptedException { final long…
lanbbz
  • 43
  • 1
  • 4
1
vote
3 answers

ExecutorService.submit() not returning after submitting the task

I want to make an asynchronous call to a function and return without waiting for the result (in Java). The code I have written for the same is: ExecutorService executorService = Executors.newSingleThreadExecutor(); executorService.submit(new…
1
vote
0 answers

Android Development: FATAL EXCEPTION: AsyncTask #1

I have been trying to learn a bit about Android Development. After a couple of "Hello World" and simple App, i decided i would like to make something i could actually use: a simple Weather App. I found a nice tutorial, so i was following…
Boguz
  • 1,600
  • 1
  • 12
  • 25
1
vote
1 answer

Terminate underlying thread with future.cancel() to re-use the thread

public class TestThreadTerminate { public static void main(String args[]) throws Exception { ExecutorService e = Executors.newCachedThreadPool(); Future f = e.submit(new Callable() { @Override …
instanceOfObject
  • 2,936
  • 5
  • 49
  • 85
1
vote
1 answer

How can I improve performance with FutureTasks

The problem seems simple, I have a number (huge) of operations that I need to work and the main thread can only proceed when all of those operations return their results, however. I tried in one thread only and each operation took about let's say…
user3155328
  • 144
  • 1
  • 7
1
vote
1 answer

How can I terminate Tasks that have timed out in multithreading?

I need to make a library in which I will have synchronous and asynchronous methods in it. executeSynchronous() - waits until I have a result, returns the result. executeAsynchronous() - returns a Future immediately which can be processed after…
john
  • 11,311
  • 40
  • 131
  • 251
1
vote
0 answers

cancel() not working while trying to cancel tasks in ThreadPoolExecutor Android

I have a few downloads that are submitted as tasks to a ThreadPoolExecutor. Now, I am creating this ThreadPoolExecutor in a global class that extends Application. I am storing all the submitted tasks in a hashmap with ids. I have a list view in a…
Shreya
  • 241
  • 1
  • 2
  • 11
1
vote
1 answer

How to implement asynchronous call with callback?

I need to make a library in which I will have synchronous and asynchronous methods in it. Core Logic of my Library - The customer will use our library and they will call it by passing DataKey builder object. We will then construct a URL by using…
john
  • 11,311
  • 40
  • 131
  • 251
1
vote
0 answers

is this a correct way to use Java FutureTask & Callable?

I'm implementing a layer to wrap a 3rd party communication layer. The contract I need to implement is: FutureTask send(Request request); My layer has an onMessageReceived method, which is called by the 3rd party when a response…
AntonKam
  • 163
  • 11
1
vote
1 answer

Calling a RESTful Web Service using FutureTask

For the time being I am using AsyncHttpClient to call RESTfull WebService from android Device and it is running fine. I want to optimize it using FutureTask as it allows us to check if a thread is finished and stuff. The code I am using now is…
Muneeb Mirza
  • 810
  • 1
  • 17
  • 35
1
vote
1 answer

Java Asynchronous process runner with inputstream reader using Futuretask

I'm trying to run an asynchronous process and getting its inputstream (if there is). This is my code: CommandCall commandCall = new CommandCall(commands); ExecutorService executor = Executors.newSingleThreadExecutor(); Future
Tobia
  • 9,165
  • 28
  • 114
  • 219