重用线程池时创建新线程时出错

xt0899hw  于 2021-07-06  发布在  Java
关注(0)|答案(0)|浏览(228)

考虑一个代码(在aws lambda中运行):

ForkJoinPool forkJoinPool = new ForkJoinPool(threadCount);
    var deleteFiles = CompletableFuture.runAsync(() ->
            files.parallelStream().forEach(file -> /*come blocking code here*/),
        forkJoinPool
    );
    deleteFiles.get();
    var copiedFiles = CompletableFuture.runAsync(() ->
            syncFiles.parallel().forEach(file -> /*come blocking code here*/)
        ),
        forkJoinPool
    );
    copiedFiles.get();
``` `threadCount` 价值是 `900` 之前的代码 `deleteFiles.get()` 工作很好,但在“第二”部分我得到:

10.934s][warning][os,thread] Failed to start thread - pthread_create failed (EAGAIN) for attributes: stacksize: 1024k, guardsize: 0k, detached.

看起来像是在第二条平行流上 `ForkJoinPool` 创建新线程,同时保留旧线程。它是?如何使线程数小于或等于 `threadCount` ?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题