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
4
votes
2 answers

Multi threaded approach to convert TIFF to PDF using iText

I am essentially trying to convert a tiff file to pdf using itext, which is fairly simple. But from what I can see TiffImage.getTiffImage is taking a lot of time to execute for larger files. My requirement is to use FutureTask and ExecutorService to…
beingsuplab
  • 155
  • 1
  • 1
  • 12
4
votes
2 answers

ScheduledExecutorService.scheduleAtFixedRate And Setting initialDelay To Date In The Past

I'm working on a scheduling system in Java that sends out reminders based on a startDate, endDate and occurrence (hourly, daily, weekly, monthly, Mondays, etc). Originally I was using Timer and TimerTask classes to schedule the reminders: Timer…
Dale Zak
  • 1,106
  • 13
  • 22
4
votes
2 answers

traversing a List object throws IndexOutOfBounds exception

I have an ExecutorService which is used to invoke a Collection of Callable obejcts and returns a List of Future objects corresponding to Callable elements in the collection. However, somewhere while traversing the list, it throws the following…
Kanav Sharma
  • 307
  • 1
  • 5
  • 13
4
votes
2 answers

Asynchronous Programming in Java when using blocking APIs

I am working on a Java project that uses certain APIs that are blocking. I would like to use asynchronous programming and callbacks, so that I don't have to block while waiting for the result. I've looked into using Java Future, but the only way I…
RagHaven
  • 4,156
  • 21
  • 72
  • 113
4
votes
2 answers

Why I am seeing lot of TimeoutException if any one server goes down?

Here is my DataClientFactory class. public class DataClientFactory { public static IClient getInstance() { return ClientHolder.INSTANCE; } private static class ClientHolder { private static final DataClient INSTANCE =…
john
  • 11,311
  • 40
  • 131
  • 251
4
votes
2 answers

How to catch RejectedExecutionException when using Scala futures?

Where should I catch RejectedExecutionExceptions when shutting down the executor ? I tried: future { Option(reader.readLine) } onComplete { case Success(v) => case Failure(e) => e match { case ree:…
lisak
  • 21,611
  • 40
  • 152
  • 243
4
votes
2 answers

FutureTask Submitted to an Executor Doesn't Run

I've written a class, a series of instances of which are intended to be called from an AsyncTask, which will return a result from the method runReport(). It creates a worker thread just fine, but for some reason it then doesn't execute the…
Captain Blammo
  • 1,897
  • 20
  • 31
3
votes
1 answer

Why Future(Failure(new Exception)) returns Success instead of failure?

I was trying the following and thinking that I'll get a failure val failure = Future { Failure(new Exception) } but instead I got Future(Success(Failure(java.lang.Exception))) Can anyone answer why?
3
votes
1 answer

Future task throws ExecutionException caused by IndexOutOfBoundsExceptionwhile I, to the best of my knowledge am using no array

the following snippet: public void handleInput() { Scanner sc = new Scanner(System.in); int x = 3; while (true) { FutureTask readNextLine = new FutureTask(sc::nextLine); …
3
votes
2 answers

Database query interruption

I have start some process in new thread: FutureTask futureTask = new FutureTask(() -> { startSomeProcess(); }, null); In startSomeProcess method I generate report for each item: for (Item item : items) { …
user5620472
  • 2,722
  • 8
  • 44
  • 97
3
votes
1 answer

a funny thing happens... ExecutorCompletionService

I have an application written in java that needs to find all the reachable hosts on the network. I use InetAddress.isReachable() to do this with a timeout of 2000 milliseconds. I look up the current local machine's IP address and based on that I…
Hector
  • 4,016
  • 21
  • 112
  • 211
3
votes
3 answers

Get result from FutureTask after canceling it

Consider a long running computation inside Callable instance. And consider that the result of this computation can have some precision depending on computation time, i.e.: if task will be cancled than it should return what is computed so far before…
Andremoniy
  • 34,031
  • 20
  • 135
  • 241
3
votes
1 answer

Wait for at least one result from Java executor without busy waiting

I have a list of Future tasks futureList.add(executor.submit(new Callable(someList))); and while those are getting executed I want to get resulting items out of it. But how can I make it without looping all the time through it and…
xwhyz
  • 1,444
  • 4
  • 21
  • 45
3
votes
2 answers

Restarting cancelled tasks in ScheduledThreadPoolExecutor

I am creating tasks with ScheduledThreadPoolExecutor and adding the Futures to a list as below in my ThreadFactory class. private static List futures; ........ ScheduledFuture sf = executor.scheduleAtFixedRate(obj, delayInMilliSec,…
Tito
  • 8,894
  • 12
  • 52
  • 86
3
votes
4 answers

Java 5: java.util.concurrent.FutureTask - Semantics of cancel() and done()

I am currently hunting a nasty bug in a multi-threaded environment using FutureTasks and Executors. The basic idea is this to have a fixed number of threads execute individual FutureTasks that compute a result that is to be displayed in a a table…
1 2
3
13 14