All Questions
Tagged with callable concurrency
38 questions
1
vote
1
answer
73
views
Why is my ExecutorService implementation performing worse than single threaded implementation?
I've been attempting to multi-thread Conway's game of life program. Part of my naive solution was to do roughly what I've done below. However, even this basic implementation performs significantly ...
0
votes
0
answers
556
views
Why does my executorservice.submit returns null?
I want to call several external APIs concurrently with multithreading in java spring, then I use it like this:
@Service
public class ServiceImpl implements Service {
public static final Logger ...
1
vote
0
answers
33
views
Are methods that return results also Callables in Java?
I have question regarding some existing working code that looks something like this:
@Autowired
ThreadPoolTaskExecutor executor;
Future<T> someMethod (Supplier<T> supplier){
Future<...
0
votes
0
answers
118
views
Callable example behaves different in debug mode in java concurrency
I'm testing the java.util.concurrent.Callable and implemented the call() in the class below but when using the isDone() of Future class, It doesn't evaluate to true and never prints the string in ...
1
vote
1
answer
169
views
How can I fix callable overlapping in Java?
I'm not sure whether the title is detail/correct or not but i can't figure out how to describe it in the title so I will try my best to describe it here
I've been trying to use callable in Java for ...
1
vote
2
answers
1k
views
Detecting a timeout exception on a Java Future without calling get() on it
I am building a library that needs to some bluetooth operations on Android. I want to return a Future instance, so whoever is using my library can call .get() on the future returned and can handle ...
3
votes
2
answers
2k
views
Does not calling Future.get cause any issue?
I am executing a certain flow wherein I submit some task to Callable and store the output in Future<> future.
In some of the cases I am not calling future.get() to retrieve the value nor am I ...
0
votes
1
answer
76
views
Execution order of callables is not consistent
I have this code where I execute sets of callables, I need one set to finish all it's work before triggering the next set. This code seems to work fine but sometimes next set would start running ...
0
votes
2
answers
198
views
Partial retrieval of data from a batch of tasks
I'm using ExecutorService for submitting a batch of tasks. I'm doing it something like this:
ListeningExecutorService exec = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(threads));
...
0
votes
1
answer
173
views
Simple program with Callable Future never terminates
I was playing around with Callable and Future and stumbled upon an issue.
This is a piece of code that never terminates and times out even though the IDE allows 5 seconds to run, and the code does ...
0
votes
1
answer
524
views
Concurrent Modification Exception in Callable class
I'm trying to split a list of objects within smaller sublist and to process them separately on different threads. So I have following code:
List<Instance> instances = xmlInstance....
1
vote
3
answers
364
views
Why Executor interface doesn't have a method, which takes Callable as a parameter?
From this answer I learned that the only difference between Callable and Runnable is that former can return a result of the execution and throw an exception.
I don't understand why Executor doesn't ...
0
votes
0
answers
38
views
ExecutorService and Callable [duplicate]
I'm implementing a simple sum programm, to sum up an array of integers using recursive multi-thread method.(ExecutorService & Callable).
But I got tons of Exceptions
public class ...
0
votes
1
answer
267
views
Display.syncExec not working inside Callable
I create a Callable which should make a syncExec call. I delegate the Callable to a subclass of RecursiveTask (ForkJoinPool) which executes the call method of the Callable. The problem is that the ...
-2
votes
2
answers
199
views
Runnable does not run inside Callable
In the following code I create a callable which creates a Runnable inside the call()-method. My problem is that run()-method is never reached (code does not get executed). Do you know why and how to ...
1
vote
3
answers
2k
views
ExecutorService.awaitTermination() never times out
I'm trying to implement a function where either the callables finish within stipulated time or the operation times out. I had hoped that ExecutorService.awaitTermination() would do this but was ...
1
vote
1
answer
675
views
Performing a long calculation that returns after a timeout
I want to perform a search using iterative deepening, meaning every time I do it, I go deeper and it takes longer. There is a time limit (2 seconds) to get the best result possible. From what I've ...
1
vote
1
answer
2k
views
Decorating Java's callable to add behavior
Let's assume we have potentially long-running task:
public class LongRunningTask {
public ReturnType doSomething() {
...
}
}
and that we want to run many of these tasks concurrently. ...
0
votes
3
answers
491
views
Get result from call that doesn't return result?
I'm using an API that makes calls for results, but doesn't return the result itself. Once the call is made, a separate method (a listener) is invoked, which contains the result. Here's an example of ...
0
votes
3
answers
2k
views
How to call a method in parallel which returns the future?
I have an async method as shown below which calls my Task class and my Task class does all the work.
@Override
public Future<DataResponse> executeAsync(DataKey key) {
Future<...
2
votes
3
answers
2k
views
java concurrent method calls with return value
I have previously posted about this topic, but I think I am misunderstanding how concurrent processing works. I essentially have a servlet with an object that collects data, and whenever a client ...
0
votes
1
answer
669
views
A strange issue when using Java's Future/Callable
I believe I understand how Future/Callable works pretty well. Like code below (2nd section), cacheLoader1 and cacheLoader2 are two instances of a Callable implementation, and its call() method is to ...
1
vote
2
answers
2k
views
java ExecutorService how to handle timeouts
I am trying to create a stub for calling multiple web services simultaneously, but I am getting an error when I am handling the CancellationException. Here is the main method
ExecutorService pool=...
1
vote
2
answers
3k
views
Start and stop Process Thread from Callable
I have a callable which starts a Thread(this Thread runs a ping process) I want to allow the user to cancel the tasks:
public class PingCallable implements Callable<PingResult> {
private ...
2
votes
2
answers
4k
views
usage of generic in Callable and Future interface?
What's the use of generic in Callable interface?
Consider this code which I copied from https://blogs.oracle.com/CoreJavaTechTips/entry/get_netbeans_6:
import java.util.\*;
import java.util.concurrent....
0
votes
2
answers
851
views
Callable and Future return exception
I have follwoing code.
Future<Integer> future = Executor.execute(callable);
Integer i;
try {
i = future.get();
} catch (InterruptedException ...
0
votes
1
answer
35
views
Java - Catching an error from either of 2 Callables as soon as it occurs
I have two Callable tasks running at the same time, launched from a main thread. Either of these two Callables can throw an error and I need this error to be passed back to the main thread and handled ...
0
votes
1
answer
140
views
runnable calls notifyall to wake itself - java
I have a class that implements Callable , X , and a class that implements Runnable , Y.
Y has a collection of X's , and when one of X's ends I want to wake Y , X has Y as a private field, can I just ...
16
votes
2
answers
15k
views
How to declare Callable to execute function returning void in Java?
Suppose I would like to run static method foo asynchronously
void foo() throws Exception {...}
Since foo throws an exception I would prefer create a Callable and invoke ExecutorService.submit with ...
3
votes
3
answers
2k
views
Do callable executes sequentially?
Whenever i run my program implementing callable, i get the output in a sequential form.
Like, here is my program :
package com.handson;
import java.util.concurrent.ArrayBlockingQueue;
import java....
0
votes
1
answer
268
views
Java fork join issue
I am learning fork-join technique in java and have written the following program. I am running a for loop (5 times) and I want to run the contents of the for loop in separate threads. This is ...
5
votes
4
answers
4k
views
How to wait for all callables to finish executing before proceeding?
I have the following code hashed out:
public class MyCallable implements Callable<Long> {
@Override
public Long call() throws Exception {
// Do stuff...
}
}
public class ...
11
votes
3
answers
19k
views
Actual implementation of Callable and Future
I am in the process of understanding fine grain util.concurrency. Where is implementation of the Java Callable and Future located in the JVM ?
I have found the Future class where it describes the ...
2
votes
1
answer
3k
views
Futures, TimeoutException, and Callables with finally blocks
Will a finally block withing a thread be called if the Callable is canceled via future.get(timeout, TimeUnit.SECONDS)?
class MyCallable implements Callable<Future<?>>{
public Future&...
4
votes
1
answer
682
views
why increment of newFixedThreadPool result in poor performance?
I'm trying to change the execution of a report and have it done in concurrency. In a 'serail mode' the execution test takes 30 seconds and when using a concurrent mode I get 27 seconds (consider that ...
1
vote
2
answers
175
views
Cancelling dynamically-loaded Callables I didn't write
I have some code that dynamically loads classes from several JARs in a directory. Because the code in the JARs is untrusted, I wish to protect the main application from poorly-coded or malicious ...
6
votes
2
answers
2k
views
Java Concurrency: How can I tell which Future belongs to which Callable during processing?
I have a collection of Callables and a ExecutorService. When I invokeAll, I get back a list of Future objects. How can I tell which Future object mapped to which Callable before the Future completes?...
15
votes
7
answers
11k
views
How can I wrap a method so that I can kill its execution if it exceeds a specified timeout?
I have a method that I would like to call. However, I'm looking for a clean, simple way to kill it or force it to return if it is taking too long to execute.
I'm using Java.
to illustrate:
logger....