208 questions
0
votes
1
answer
292
views
JUnit Test for CompletableFuture supplyAsync
How do I mock and write unit tests for the below function? I am finding it difficult to write unit tests for CompletableFuture. If the function does not cancel the task within 3 minutes, I want to ...
1
vote
2
answers
513
views
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 ...
1
vote
1
answer
55
views
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 ...
-1
votes
1
answer
650
views
ScheduledFuture returns null when a task is submitted or scheduleAtFixedRate
I am trying to schedule a job to run every 10 minutes using ScheduledThreadPoolExecutor. There are 10 threads in the thread pool.
Code looks like:
ScheduledThreadPoolExecutor executor = new ...
2
votes
1
answer
658
views
Why is spring ListenableFuture.cancel throwing CancellationException
I am doing some task execution using the spring ThreadPoolTaskExecutor class using the submitListenable(Callable<T> task) method.
When I call cancel(true) on the listenablefuture returned by the ...
0
votes
0
answers
302
views
How to mock callable futureTask.get(long, TimeUnit) method to return a response
I have a callable FutureTask that is getting executed using ExecutorService.
FutureTask<Optional<Attestation>> attestationDbTask
= new FutureTask<Optional<Attestation&...
1
vote
0
answers
116
views
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:
...
0
votes
1
answer
344
views
FutureBuilder runs twice even it is not supposed to
This is my code:
class HomePage extends StatefulWidget {
const HomePage({Key? key}) : super(key: key);
@override
State<HomePage> createState() => _HomePageState();
}
class ...
0
votes
1
answer
133
views
How to send data from one future task to another future task in flutter?
For example there are 4 Future tasks in flutter that are dependent on each other and after these tasks are completed Navigator.pushReplacement is called to change function. By dependent it means that ...
0
votes
0
answers
218
views
Flutter-Web : Future doesn't change the variable
I've this code in a Flutter page.
This code is supposed to show to the user that his orders had been send to the database.
I use a future with the function .then and I should get the response status ...
-2
votes
1
answer
168
views
Async API using Future never completes [duplicate]
I try to make an API aysnchronous as:
Future<Integer> fASync(int x) {
return new FutureTask(() -> {
try {
Thread.sleep(new Random().nextInt(1, 3) * 1000);
...
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 {
...
1
vote
0
answers
195
views
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 ...
-1
votes
2
answers
237
views
Java's CompletableFuture : time of ExecutionException
When working with CompletableFuture any potential errors from computing the value are exposed via the get() method throwing an ExecutionException. I can of course log this exception at the time of ...
0
votes
1
answer
2k
views
Return a value inside a CompletableFuture in another CompletableFuture and return that future
I want to get a value inside a CompletableFuture (in this case clonedWorld) in another CompletableFuture and return that future. This is my code, and I'm stuck here:
@Override
public CompletableFuture&...
1
vote
3
answers
328
views
type 'Future<DateTime>' is not a subtype of type 'DateTime'
In my Flutter app I'm fetching some datetime info from an API but getting this error. I'm using Provider.
My display widget has this in didChangeDependencies:
_userDateTime = Provider.of<TimeZones&...
0
votes
0
answers
90
views
JNA callback method wont be called until futureTask.get() timeout
If I run like this, the callback block will not run so future.get() will block forever:
FutureTask<Long> futureTask = new FutureTask<>(System::currentTimeMillis);
boolean login = ...
0
votes
1
answer
459
views
Android: Wait for userinput but set a timeout
In my application the user is prompted with an exercise and he has 5 seconds to solve it, if he does not respond in time, the next exercise should be shown.
My question is: What would be the best way ...
0
votes
1
answer
271
views
FutureTask get() method may distable LockSupport.park
i found FutureTask get() method may distable LockSupport.park in oracle jdk8
my code is :
ExecutorService service = Executors.newFixedThreadPool(1, (r) -> {
Thread thread = new ...
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 ...
2
votes
2
answers
170
views
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 ...
1
vote
1
answer
2k
views
How to timeout a java thread from main Thread?
I am new to working with ExecutorService, Future, and Runnable in java to set up timeouts on threads. I am working on a program where my main thread will call another thread to parse an XML file and (...
0
votes
1
answer
587
views
Constructing a DAG of cancelable Java tasks
I want to create a DAG out of tasks in Java, where the tasks may depend upon the output of other tasks. If there is no directed path between two tasks, they may run in parallel. Tasks may be canceled. ...
5
votes
3
answers
6k
views
Convert a Stream to a Future in Flutter
a Flutter beginner here so if my question is stupid don't mind it...
How can I convert a Stream to a Future?
I have a Stream that just calls the requested URL multiple times because it's a Stream. I ...
0
votes
2
answers
2k
views
Why this future function is returning empty list flutter
I am new with flutter having issues with the future functions. I had a single await function on other screen and its returning list but when I use multiple await function in a single future function ...
0
votes
2
answers
2k
views
Flutter - Pull to refresh with RefreshIndicator in FutureBuilder
Edit: Minimal reproducible example. Please have a look at the refresh-Method in main.dart.
I'm using a FutureBuilder to display the result of a network request. I call my fetch method in initstate (...
0
votes
0
answers
93
views
Better method to replace AsyncTask being deprecated to get data from server
I see there are several options to replace AsyncTask now being deprecated.
I get a little unsure or confuse or both which option is best to use.
Actually my asynctask get data form a server, which can ...
3
votes
1
answer
621
views
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?
0
votes
1
answer
282
views
What is a Best way to handle Multi threading with callbacks in Kotlin?
I want to display multiple windows in a queue after some wait time. So what is the best way to implement the same?
ThreadPoolExecutor
FutureTask
Coroutines
or any other way in Kotlin?
0
votes
1
answer
2k
views
Mockito Mock method parameter of type Future<T>
I have the below code:
public final class JoinableTaskPool<T> extends ABC {
public Future<T> submit(final Callable<T> task) {
executorService.submit(new Runnable()...
2
votes
1
answer
268
views
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 ...
0
votes
1
answer
97
views
Trying to make sequential executing of futures. What is wrong?
I am trying to execute function which returns Future sequentially
So, I have a collection
val in = Seq(1, 1, -1, -2, 3, -4, 5, 6, 7, -1, -2, -9, 1, 2, 2)
and function to process every int in this ...
0
votes
0
answers
39
views
Why does only some of my objects get created using std::async
I have a loop that pushes back calls of std::async that are used to create objects in the pointed function and emplace them back to another vector. All the calls are pushed to the futures function and ...
-1
votes
1
answer
22
views
Why even after putting await keyword my app will show 0?
I have called trigger function inside initState function.In trigger function i will be taking data from an API and i parsed the data using storeddata.fromjson function. Then afterwards i will store ...
0
votes
0
answers
303
views
How to completely stop / terminate a task that has already been submitted to an ExecutorService in Java?
Problem : I have an use case where I want to cancel a task that has already been submitted to an executor service. future.cancel() is not helpful to me as the task does not go to wait() / sleep() ...
3
votes
1
answer
927
views
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<String> readNextLine = new ...
0
votes
2
answers
110
views
Exception type Future(void) in not subtype of Future<AnimationController>
the code below performs the creation of a layout in flutter, to create the layout I must first make sure that the set function is executed to make it use future builder but when I run the code I have ...
0
votes
1
answer
833
views
Is there a way I can use Future values in Dart to fill Textfields?
I've been learning Dart with flutter and was creating Weather App for practices , I managed to successfully create the UI , I used Dark Sky weather API since it has 7 day weather forecast but instead ...
0
votes
1
answer
251
views
What is the difference between the two uses of FutureTask?
use thread pool:
ExecutorService exec = Executors.newFixedThreadPool(5);
FutureTask<Integer> ft = new FutureTask<Integer>(() -> rpcMethod());
exec.submit(ft);
call run method:
...
4
votes
1
answer
2k
views
When to use Scala Futures?
I'm a spark Scala Programmer. I have a spark job that has sub-tasks which to complete the whole job. I wanted to use Future to complete the subtasks in parallel. On completion of the whole job I have ...
-1
votes
1
answer
652
views
Computation with Futures avoiding Await method
I have funtion which is calling computeParallel() function which is calling 3 Futures F1,F2,F3 and returning String as return type.
def computeParallel():String =
{
val f1 = Future { "ss" }
...
0
votes
2
answers
219
views
Parallel Computation with Scala Futures [closed]
I have a Function that computes two sub-functions like this.
def someFutureMethod1(input: Int): Int = {
input + 1
}
def someFutureMethod2(input: Int): Int = {
input + 12
}
def ...
0
votes
1
answer
2k
views
Get values for variables in FutureBuilder and use in layout
Variable dependent widgets are processed before FutureBuilder finishes execution.
With the following code 'subtraction was called on null' error appears.
- Is it possible to get word (problem) ...
2
votes
0
answers
2k
views
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 ...
1
vote
0
answers
75
views
How to prevent swapping of multi threaded response in Concurrent Future Java?
Check the below code. There is a problem in multi threading where results from each thread are swapped
We have tried using withWheelColor.isDone and withWheelColor.isCancelled and also surrounded it ...
3
votes
2
answers
3k
views
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 Callable&...
1
vote
1
answer
661
views
How to add programmatically List Widgets to TabBar?
I am building an application that connects and sends requests to an HTTP server and when gets the responses parses them into a JSON Object and displays the output.
The problem occurs when i use the ...
-1
votes
1
answer
852
views
Spring re-try withing future tasks not working
I have a spring-boot application which which needs to call external APIs.
If there are 'n' external calls, 'n' future tasks will be created and rest calls will be made. Problem here is if any of the ...
0
votes
1
answer
222
views
how to execute code after the exception in scala using Try
i have two actors they can either return the Result which is a boolean value in my case or they can throw an exception here is my code
val futureA: Future[Boolean] = ask(ActorA, MessageA(obj)).mapTo[...
1
vote
0
answers
125
views
Cancellation problem when using nested future on Java
If the Future is nested for different jobs is created and given the same timeout for both Future, the main Future is not canceled. But if the timeout for the child Future is less than the main Future, ...