CompletableFuture.allOf() and Executor.shutdown()

这是两块内容 CompletableFuture.allOf() allOf()会非阻塞等待所有的CompletableFuture都完成,无论这些task中是否有抛出异常,也就是说即便其中有某些抛出了异常,allOf()的CompletableFuture调用join()阻塞等待时也不会立即抛出异常,而是等所有需等待的都完成,才会抛出异常,这也是allOf的含义之一 Executor.shutdown() 当ThreadPool调用shutdown()时,调用后只是不再接收新的Task,已提交的task会继续执行无任何影响,并且对该方法的调用并不会阻塞等待创建的thread结束。但如果main thread结束,那应该都结束。 另外就是当使用ThreadPool来run CompletableFuture时,若每次都new ThreadPool,则InheritableThreadLocal会正常,若使用默认或预定义的ThreadPool,则InheritableThreadLocal会失效(因为其只会在Create Thread时传递,而ThreadPool中的Thread是share的,而非每次都Create New)

lWoHvYe 无悔,专一