How to ask CompletableFuture use non-daemon threads?

后端 未结 2 1196
孤独总比滥情好
孤独总比滥情好 2021-01-06 08:10

I have wrote following code:

 System.out.println(\"Main thread:\" + Thread.currentThread().getId());
 CompletableFuture future = CompletableFut         


        
2条回答
  •  一整个雨季
    2021-01-06 08:32

    Add this line:

    ForkJoinPool.commonPool().awaitTermination(5, TimeUnit.SECONDS);
    

    to the main method after running your future. I'll block until all tasks in the pool have been completed.

    Blocks until all tasks have completed execution after a shutdown request, or the timeout occurs, or the current thread is interrupted, whichever happens first.

提交回复
热议问题