How to ask CompletableFuture use non-daemon threads?

后端 未结 2 1217
孤独总比滥情好
孤独总比滥情好 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:49

    The javadoc for runAsync() says:

    Returns a new CompletableFuture that is asynchronously completed by a task running in the ForkJoinPool.commonPool() after it runs the given action.

    There is another version of runAsync() where you can pass an ExecutorService.

    Thus: when the default commonPool() doesn't do what you want - then create your own ExecutorService instead.

提交回复
热议问题