I'm trying to play with async java in my intellij local. My intention is that i will call calucalateAsync() method from main method and then put the debug point on System.out.println("calculate async was called");.
Ideally the submitted task to executors service should be executed concurrently, but the issue is until the execution of the main method is being done, the task is never being executed. Please let me know
Please find below the code:
CompletableFuturePlay.java
public class CompletableFuturePlay {
public void calculateAsync() throws InterruptedException {
System.out.println("inside calculate async method");
Executors.newFixedThreadPool(10).submit(() -> {
System.out.println("inside the submitted task");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("completed the thread");
return;
});
System.out.println("outside executores block");
}}
PlayGround.java
public class PlayGround {
public static void main(String[] args) throws InterruptedException, ExecutionException {
CompletableFuturePlay completableFuturePlay = new CompletableFuturePlay();
completableFuturePlay.calculateAsync();
System.out.println("calculate async was called");
}}
