Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
0 votes
2 answers
88 views

How can a Callable return a value from a predefined void callback?

I am using a data-related API interface which has a key void callback function that is automatically invoked to mark the end of some IO operations. I want to make the class Callable<String> and ...
limestreetlab's user avatar
-1 votes
1 answer
103 views

Make a `Callable` of my `Runnable` in Java

I have some tasks defined as Runnable objects. I want to invoke those tasks by using the invokeAll or invokeAny methods on ExecutorService. The problem is that those methods take a collection of ...
Basil Bourque's user avatar
0 votes
0 answers
126 views

CompletableFuture supplyAsync, thenApplyAsync, thenAcceptAsync working incorrect

I made Async CompletableFuture so that I would first make a payment and then sleep for 10 minutes. And this was repeated endlessly. But sleep once doesn't work anymore public class PaymentWorker ...
Nodirbek Sirojiddinov's user avatar
-1 votes
1 answer
76 views

Spring Boot Asynchronous Controller via Callable not working

I want to make an endpoint that is asynchronous with Spring Boot. I want to avoid Futures and thus @Async because it forces the use of futures. I read and applied the code from this article : https://...
Genku's user avatar
  • 39
-1 votes
2 answers
108 views

How to pass a callable object as runnable object? Can we type cast Callable to Runnable?

How is the below structure possibly working? Please explain. Thanks in advance. public abstract class AbstractCallableClass { protected abstract V getCallable(); public void passRunnable() { ...
Utkarsh's user avatar
-2 votes
1 answer
140 views

Best way to call common methods from a Callable class?

I use java classes of type Callable (up to 200 in parallel), which call a method of a tool class (centralizing common methods), and I notice that if this method is not 'synchronized', I get errors. I'...
vinsse2001's user avatar
0 votes
0 answers
84 views

Java Callable Attempts to Complete Prematurely

I have a method that is called with multi threading and runs to around 99% completion. At this point it runs the next method which needs the first method to of finished running before attempting as it ...
PondleDondle's user avatar
-1 votes
1 answer
351 views

Need help for CompletableFuture or Callable Future

I am facing issue for finding out which will be the best way for my below scenario. I wanted to call 1 API by using multiple threads at a time and wanted to merge their response to make a list. First ...
mohan's user avatar
  • 457
0 votes
1 answer
72 views

Creating objects and overriding their method constructors from java to kotlin

PaintBuilder.newBuilder() .addString("Method: ", new Callable<String>() { @Override public String call() throws Exception { return userMethod; } ...
TheDeverino's user avatar
2 votes
1 answer
404 views

How to return value from Callable with CountDownLatch?

I want to use CountDownLatch with Callabe interface. I have Person class implements Callable interface which has CountDownLatch and Integer, Person#call() method returns integer value and within ...
stewie's user avatar
  • 33
1 vote
1 answer
845 views

Does callable also gets executed in a thread?

When we pass a runnabble to an executorService like Future future = executorService.submit(runnable); // As here executorService maps the object into instance of new FutureTask(runnable); and after ...
Adarsh Verma's user avatar
1 vote
1 answer
120 views

Facing issue while using invokeAll to fetch Future object in ExecutorService

Facing below error while fetching Future object by using invokeAll Method. Iam trying to implement ExecutorService to call parallelly. ERROR>>>>>>>>>>>>>>>&...
Monojit's user avatar
  • 157
0 votes
1 answer
220 views

Should I use Thread and .join or Callable along with Future and .get?

I am writing a simple thread that simply run a process and reads the InputStream. While reading the input, if it finds a certain string it sets a boolean to true. Then when I need to check that ...
zaxunobi's user avatar
  • 930
0 votes
1 answer
127 views

How to wait until for few callable tasks complete and then execute

I want to execute some processors in two threads.. few of them are independent and could run anytime but few of them have dependency.. whenver order of execution reaches to that processor i want to ...
Dungeon Master's user avatar
1 vote
0 answers
36 views

Mockito - verify a method with Callable<> as parameter [duplicate]

I have a following class: public class Task { public <V> V run(Callable<V> callable) { //... callable.call() } } And I have a class that uses the above: public ...
Tirlipirli's user avatar
-1 votes
1 answer
277 views

When is start method invoked by ExecutorService in Java?

I'm learning about ExecutorService in a simple Spring Boot project. And I know that ExecutorService uses submit method to submit tasks and it will uses different threads for every task. And I don't ...
elvis's user avatar
  • 1,118
0 votes
1 answer
105 views

Using Callable In ROOM

I am building TODO app with room database and MVVM. So since I can't use ROOM in main thread,I searched for solutions and came across "Callable" which is just what I need! Since I have more ...
HoLoGram's user avatar
  • 169
0 votes
1 answer
203 views

Re-execute Callable if it fails

Having an ExecutorService that executes a Callable that is supposed to be always running, what is the best implementation to relaunch it when an error happens? Currently my source code looks something ...
Chazz1's user avatar
  • 133
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 ...
DSb1rd5's user avatar
  • 33
-1 votes
1 answer
368 views

Executor service returning incorrect response

I am creating future list from a list of calls to executor service submit method based on student ID. The response from service is not returning for all studentId's. It runs for the right number of ...
Bhanu's user avatar
  • 211
1 vote
1 answer
614 views

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 { ...
AlwaysLearning's user avatar
2 votes
1 answer
5k views

I need not wait until executing async method call() [duplicate]

I need to do some async method. And not wait until it executing. I try with Future but it not help. Future<Boolean> future = executorService.submit(new MyCallable()); LOGGER.info("...
Alexei's user avatar
  • 15.6k
0 votes
0 answers
30 views

Can't sync code inside java class Callable

java 8 my snippet: private ThreadedApplicationEventPublisher threadedApplicationEventPublisher; private final ExecutorService executorService = Executors.newSingleThreadExecutor(); private ...
Alexei's user avatar
  • 15.6k
1 vote
1 answer
101 views

Why ExecutorService is not shutdown after invokeAny returns a result?

As I was experimenting with Future and Callable in Java, I had a result I cannot make sense of with my current understanding. The below scenario is for demonstration purposes only. From my ...
recepinanc's user avatar
0 votes
1 answer
995 views

Is there a way to update a local variable through Mono.fromCallable()'s return value of an api inside a while loop?

I need to run GET requests multiple times until the return of the GET is an empty array. Currently I have been doing it with a global receivedAllApiData variable I update in getApiValues if it is an ...
Justin's user avatar
  • 1
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 ...
Dhana D.'s user avatar
  • 1,720
0 votes
1 answer
651 views

Can Java run multiple instances of the same socket in parallel?

I am for-looping multiple socket connections via a Callable with Future Boolean to open sockets to multiple IPs in parallel. If each IP is different, it seems to work fine. However when data needs to ...
Imran's user avatar
  • 85
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<...
Cleo's user avatar
  • 43
0 votes
2 answers
595 views

Java - Callable Out of memory solution?

Hi Guys can you help me about the error that I've encountered on my Java program. I do the Callable implementation with a loop, Basically I need to send a request to another webservice and I will be ...
absolute's user avatar
-1 votes
1 answer
237 views

Concurrency feature of JavaCallable-Future using AWS-SQS

Current-approach: For Spring Boot app, in AWS environment: The service-layer spawns 5 threads, using ExecutorService --> Callable-Future for concurrent processing. On completion, each callable-...
Prashant-M's user avatar
0 votes
1 answer
195 views

Java Callable and Future not running asychronously

I am using Java 7. I have a method I would like to execute in a new thread (asynchronously) and allow the rest of the process to continue. However, I have the following code, but it still executes ...
Richard's user avatar
  • 8,857
1 vote
0 answers
252 views

pass context to callable

I am creating several tasks to download some files from the internet and I want to access the context in MyTasks.class . What is the best way? public class MyTasks { public Callable<File> ...
user avatar
-1 votes
1 answer
139 views

Submitting FileInputStream via ExecutorService

After using this as a guide I'm trying to send a FileInputStream to two APIs concurrently, if either of them fails we error out. I have two callables private void submitCallablesWithExecutor(final ...
FullStack's user avatar
  • 457
-1 votes
1 answer
90 views

How can I create multithreaded code using ThreadpoolExecutor & Callable Future

I have an execute method which is running multiple test cases one by one, the test cases are passed in a list of Strings arrays. I am trying to run this test cases in multi-threaded way, also writing ...
Dead pool's user avatar
  • 123
4 votes
1 answer
628 views

Program won't exit in using Callable and Future

IDE: IntelliJ JDK: Java 11 While was testing a sample code from lecture, I have found something really weird that my program just won't stop, even though there aren't any loop! import java.util....
co_lin's user avatar
  • 135
0 votes
2 answers
2k views

java callable with multiple methods

I`m trying to implement a java callable with multiple methods and my situation is like this: interface FsHandler { boolean existDirectory(); boolean existFile(File); ... } interface ...
user2262368's user avatar
0 votes
0 answers
241 views

I am using AsyncTaskExecutor to execute a callable method. But after few calls, it does not call the code in callable method

I am using AsyncTaskExecutor(org.springframework.core.task.AsyncTaskExecutor) to execute a callable method which in turns download pdf using async call. But after few downloads , it does not execute ...
shirin kulkarni's user avatar
0 votes
0 answers
463 views

Make asynchronous response write when executor service requires object?

A client request is handled by doGET which calls a third-party API. This third-party API then does not send a response back to doGET but calls my other endpoint to be handled by doPOST. I now need to ...
a13e's user avatar
  • 908
0 votes
0 answers
160 views

How to Access the Callable Task's input parameter inside thenAccept Method?

I have the following methods to invoke some logic in a non-blocking way. public void runParallelFunctions(Callable<Map<String, String>> invokerTask) { Supplier<Map<String, String&...
AnOldSoul's user avatar
  • 4,197
1 vote
1 answer
1k views

Spring boot instantiate multiple components

I have a callable type class. It is a annotated with @component. I would like to create multiple instances of the callable class. To do so, I am using the application context. The problem is it simply ...
Nesan Mano's user avatar
  • 2,156
2 votes
3 answers
2k views

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 ...
user avatar
1 vote
1 answer
10k views

Spring Boot Callable - 401 Unauthorized: [no body]

I am using Callable interface inside a Spring Boot Application that sends auth request: public class TestCallable implements Callable<TestDto> { TestEntity testEntity; public ...
Curious Raccoon's user avatar
0 votes
2 answers
245 views

Using Callable and ExecutorCompletionService, future.cancel() does not work

I am using a bunch of callables to search a list in individual chunks, once one returns true, I want to cancel all the other running callables. future.cancel is not cancelling them My NumberFinder ...
HelloWhatsMyName1234's user avatar
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 ...
user avatar
0 votes
1 answer
853 views

reference to submit is ambiguous: <T>submit(Callable<T>) in ExecutorService and method submit(Runnable) in ExecutorService match

I am registering a callable and saving it into a future object like this: final Future<SomeObject> objectFuture= Executors.newFixedThreadPool(5).submit( () -> ...
Siddharth Shankar's user avatar
0 votes
0 answers
86 views

How to execute more than one Future and wait for it done before for loop in java?

hi how do i execute 3 callable function so i don't have to wait when do another process and in some point i will have to wait them for complete before i can move to my next line of my code properly? ...
Ke Vin's user avatar
  • 3,730
2 votes
3 answers
1k views

How to call a method in parent class inside of Lambda function in Java?

I was trying to write the following piece of code, but the error happened on line return super.getAge("Jack"); It showed "The method getAge() is undefined for the type Object". I ...
Gaoyang's user avatar
  • 41
0 votes
1 answer
249 views

How to get server status using multi-threads periodically

The below code works fine and it connects to a given server (host, port) and gets the connection status. What it does is: PollService implements the Callable interface and connects to a server(host, ...
newday's user avatar
  • 3,878
1 vote
1 answer
3k views

ExecutorService to execute a single task n times by multiple threads (n thread "races")

I need to execute a single task by multiple threads, such that when the first thread finishes and before any other thread finishes, all the threads are stopped and start the same task all over again. ...
user avatar
1 vote
0 answers
152 views

ResultSetHandler problems in multithreaded parallel queries

I am trying to make several read queries in parallel in Oracle database from a Java application. I use CallableTasks to make these queries. The sample of the Callable Task is as follows: public class ...
wakarK's user avatar
  • 36

1
2 3 4 5
8