I created an example, i want to know how can I return a value using the CompletableFuture
? I also changed the CompletableFuture<Void> exeFutureList
to be CompletableFuture<Integer> exeFutureList
but eclipse always suggest to
set it back to Void.
Please let me know how to return value using CompletableFuture.
Code:
public class MainClass {
static ExecutorService exe = null;
static CompletableFuture<Void> exeFutureList = null;
public static void main(String[] args) {
exe = Executors.newFixedThreadPool(1);
exeFutureList = CompletableFuture.runAsync(new RunClass(8), exe);
}
static class RunClass implements Runnable {
private int num;
public RunClass(int num) {
// TODO Auto-generated constructor stub
this.num = num;
}
public void run() {
// TODO Auto-generated method stub
this.num = this.num + 10;
}
}
}