2021年5月1日星期六

Java Calling function from other class async

I have a problem. I am trying to call a method from another class async. Here is the function I am trying to call:

public class CandlestickDriver {        public void run(String market, String coin, String period, boolean once, boolean firstRun) {        }    }  

And in my MainClass, I have the following code:

CompletableFuture.supplyAsync(CandlestickDriver::run);  

But that gives me the error:

The type CandlestickDriver does not define run() that is applicable here

I also don't see a way how I can pass the paramters to that class, so how can I fix this. It's important that I can use some kind of chaining, because when that method is done, I need to call another method, so I found the command .thenApply(), but also for that I need to pass paramters.

How can I fix my error and pass parameters?

UPDATE

I tried the following:

CompletableFuture.supplyAsync(() -> new CandlestickDriver.run("USDT", "BTC", "1d", once, firstRun));  

But that give me an error on supplyAsync : The method supplyAsync(Supplier<U>) in the type CompletableFuture is not applicable for the arguments (() -> {})

And I also get an error on CandlestickDriver.run: CandlestickDriver.run cannot be resolved to a type

How can I fix this?

https://stackoverflow.com/questions/67352019/java-calling-function-from-other-class-async May 02, 2021 at 08:32AM

没有评论:

发表评论