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

Why is spring ListenableFuture.cancel throwing CancellationException

I am doing some task execution using the spring ThreadPoolTaskExecutor class using the submitListenable(Callable task) method. When I call cancel(true) on the listenablefuture returned by the submit method I get a cancellation exception and I…
joey
  • 21
  • 2
2
votes
3 answers

FutureTask cancel()

Basically I have the following snippet, (let [task (FutureTask. fn) thr (Thread. task)] (.start thr) ;;wait for signal... (.cancel task true) (.stop thr)) Problem is once in a while cancel does not work, AFAICT cancel causes and…
Hamza Yerlikaya
  • 49,047
  • 44
  • 147
  • 241
2
votes
3 answers

FutureTask get vs run, task never finishes

I am learning Callables and decided to make a very simple program. The problem is that the Thread is blocked when I call getFutureTask(); Thread.State: TIMED_WAITING (on object monitor) Could you please tell me why is it so and why does my program…
user15204218
2
votes
2 answers

Do I have to manually process interrupt in FutureTask?

I'm currently trying to understand how FutureTask.cancel(true) is working, this is the relevant piece of official doc If the task has already started, then the mayInterruptIfRunning parameter determines whether the thread executing this task should…
starwarrior8809
  • 361
  • 1
  • 10
2
votes
1 answer

Scala - Return value from Callbacks

I am fairly new to scala programming. Can someone please help me with return value from callbacks. How could I return a callback value as JsObject from the calling method? I am using the Play2 framework with an actor system. Please let me know if my…
user2918406
  • 139
  • 2
  • 9
2
votes
0 answers

How to set a timeout on a Web Service call in JAVA?

Hello I must update an application in my company, so I have to add a timeout on the call of a client's web service (I have just a tips about the framework Spring). How can I do that ? I have an application who can call some client's Web Services,…
Julien.H
  • 21
  • 4
2
votes
2 answers

Java ExecutorsService submit a FutureTask get on Future returns null

I have this snippet. final ExecutorService executor = Executors.newFixedThreadPool(3); final Runnable runnable = ()->{System.out.println("Inside runnable run method");}; final Callablecallable = ()->{System.out.println("Inside…
chiperortiz
  • 4,751
  • 9
  • 45
  • 79
2
votes
2 answers

Java FutureTask - Multithreaded call to get()

I have the following two methods in a class: private MyDef myDef; private FutureTask defFutureTask; public synchronized void periodEviction() { myDef = null; } public MyDef loadMyItems() { // if it's not ready use a future -…
ha9u63a7
  • 6,233
  • 16
  • 73
  • 108
2
votes
1 answer

Catching dangling or unused Futures in Scala

A common problem in our Scala code is that a call that returns a Future[T] will not be awaited (we commonly use the scala-async library because many of us are familiar with async/await from C#) or used at all; it is simply discarded. Is there any…
2
votes
1 answer

How to kill the executing task completely using callable futuretask in 1.8

I have a certain process which can be execute in a Thread. I need to stop the processing completely after certain time Example :90 seconds. I read we have an option in futuretask to set the timeout for a thread. But i am getting the timeout…
TikTik
  • 347
  • 2
  • 8
  • 22
2
votes
2 answers

Wait for FutureTask completion in game loop

I want to setup a FutureTask for a expensive path finding task. So I created this Callable class. public class GetPath implements Callable> { private Coordinate start; private Coordinate end; public GetPath(Coordinate…
Madmenyo
  • 8,389
  • 7
  • 52
  • 99
2
votes
1 answer

How can I eliminate sonar qube issue when calling the run method of FutureTask?

I have the below code for which Sonar Qube is raising a critical error. public void onMessageReceived(Message message) { if((message.getTargetInstanceId() != Message.ANY_TARGET) && (message.getTargetInstanceId() != this.instanceId)) { …
AnOldSoul
  • 4,017
  • 12
  • 57
  • 118
2
votes
1 answer

How can I cancel a task of ExecutorService on click of a button?

I have a list of items on which user can click for download. For which I am having this code: //Maintained this in my ListAdapter class so that if user clicks on cancel download i can do: // tasks.get(info.getFieldID()).cancel(true); public static…
user2234
  • 1,282
  • 1
  • 21
  • 44
2
votes
2 answers

Running asynchronous code in java with timeout

In a web server i wrote, each request invokes a list of actions. Some of these actions aren't as critical as others, so I would like to run them in a background thread. Also, since they aren't that important I don't care if one of them fails…
gillyb
  • 8,760
  • 8
  • 53
  • 80
2
votes
3 answers

Inject Context (CDI/servlet) into new FutureTask Thread

I found that a new thread created in the servlet donot contain the servlet/CDI context. I created a HelloWorld servlet (given below) to experiment with this problem. In the below example, you'll see that I am running 'doIt()' function in a new…
Ankit Singh
  • 2,602
  • 6
  • 32
  • 44