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
2
votes
1 answer

how do FutureTasks and CachedThreadPool work

I currently have code that does the following: private final static ExecutorService pool = Executors.newCachedThreadPool(); public void foo(){ FutureTask first_task = createFutureTask(); FutureTask second_task =…
Aly
  • 15,865
  • 47
  • 119
  • 191
2
votes
2 answers

How run task in future in java at a particular date

I have have to call a method in future so i found some example Link are there Link 1 link 2 But I have to run it ONE TIME only. at Date and Time : 11-03-2014 10:15:20 (dd-MM-yyyy HH:MM:SS) I how do it??
java baba
  • 2,199
  • 13
  • 33
  • 45
2
votes
1 answer

How to get the data from the map whenever it is present?

Below is my factory code which starts the background thread TempScheduler - public class TempClientFactory { public static IClient getInstance() { new TempScheduler().startScheduler(); return ClientHolder.INSTANCE; } private…
AKIWEB
  • 19,008
  • 67
  • 180
  • 294
2
votes
2 answers

How do I interrupt a thread given a Future object?

I want to start a thread and cancel it if it doesn't finish within 5 seconds: private final class HelloWorker implements Callable { public String call() throws Exception { while(true) { if (Thread.isInterrupted()) { …
Popcorn
  • 5,188
  • 12
  • 54
  • 87
2
votes
2 answers

What will happen when two threads execute cache.putIfAbsent at the same time?

I am learning Java Concurrency in Practice, but some code confused me: private final ConcurrentHashMap> cache = new ConcurrentHashMap>(); private final Computable c; public Memoizer(Computable c) { this.c…
znlyj
  • 1,109
  • 3
  • 14
  • 34
2
votes
2 answers

How to check when an executor has finished running a particular Runnable

I was looking for a way to wait and be notified when a particular Runnable has finished executing within an executor. I found a FutureTask that has a method get, however, this returns a value. My program does not expect a return value; is there any…
Karan
  • 14,824
  • 24
  • 91
  • 157
2
votes
2 answers

Design issue: is this doable only with producer/consumer?

I'm trying to increase performance of indexing my lucene files. For this, I created a worker "LuceneWorker" that does the job. Given the code below, the 'concurrent' execution becomes significantly slow. I think I know why - it's because the futures…
adhg
  • 10,437
  • 12
  • 58
  • 94
2
votes
5 answers

Java: Logging FutureTask exceptions

I've got an application which regularly submits tasks to be executed in a dedicated thread. Those tasks are FutureTask and the thread is no more than an infinite loop which executes the jobs as they get into a queue, going to sleep if…
user683887
  • 1,260
  • 1
  • 10
  • 20
1
vote
1 answer

ExecutionException thrown but without a cause

I have a futures task that is doing some I/O operations over the socket to a server. When I use the get() method of the task to retrieve the result, I am getting ExecutionException, but with no cause i.e. getCause() returns null. In what scenario…
hari_sree
  • 1,508
  • 3
  • 12
  • 24
1
vote
1 answer

How can I use Pinput validator with a http request?

I`m building a code and I would like to validate the input using the Pinput widget, and I noticed that the method validator receives a String? function. I`m making a http request to validate if the input is correct or not, but as I can`t put async…
1
vote
1 answer

I have a task with 2 futures, one is updating a counter while the other will copy and send the counter. How do I manage the counter?

I have a task, which has two futures, both being waited on. The first future consumes data from a channel, transforms it and sends it out another channel, incrementing a stats counter. The second future waits on a different channel for a "stats…
Bruce
  • 11
  • 3
1
vote
0 answers

Running Async FeatureTask in Java stream

I'm using Java-Streams to run FutureTasks and get the results. It generally runs ok. But in recent days, if the API calls are frequent, the system blocks. What might be a reason of this problem? Code: private List
丁双喜
  • 11
  • 1
1
vote
2 answers

How do I efficiently process multiple results from an Executor Service

I'n new to ExecutorService, but am unsure about my approach to this. I could be dealing with up to 100 threads for a known task. I'm using the general format below, where I create a List of FutureTasks, then submit these to the ExecutorService. The…
1
vote
1 answer

What is the use of java.util.concurrent.FutureTask if it blocks main?

I am rather new to learning java.util.concurrent. While implementing a basic program (below) it's clear that the main thread waits for Callable to return a value. public class FutureTaskTutorial { public static void main(String[] args)…
1
vote
0 answers

FutureTask in android

I'm very new to Android so maybe my question is a bit of a beginner. I want to use the futureTask method in my program, but I really do not know how to use it. I have a sample code of this method and I want to combine it with my own code.…
error404
  • 31
  • 7