ForkJoinPool线程池大量线程WAITTING

"ForkJoinPool.commonPool-worker-18" #34 daemon prio=5 os_prio=0 tid=0x000001b4ce932000 nid=0x3520 waiting on condition [0x0000006b31efe000]

   java.lang.Thread.State: WAITING (parking)

        at sun.misc.Unsafe.park(Native Method)

        - parking to wait for  <0x000000072a2989a0> (a java.util.concurrent.CompletableFuture$Signaller)

        at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)

        at java.util.concurrent.CompletableFuture$Signaller.block(CompletableFuture.java:1707)

        at java.util.concurrent.ForkJoinPool.managedBlock(ForkJoinPool.java:3324)

        at java.util.concurrent.CompletableFuture.waitingGet(CompletableFuture.java:1742)

        at java.util.concurrent.CompletableFuture.get(CompletableFuture.java:1908)

        at io.minio.MinioClient.putObject(MinioClient.java:1325)

ForkJoinPool线程池大量线程WAITTING_第1张图片

 使用stream流的parallel多线程执行,默认使用的是ForkJoinPool线程池,minio客户端默认也是使用ForkJoinPool线程池,那么如果父线程所用的线程池和子线程所用的线程是同一个的话,在并发的情况下,会发生一种情况,父线程的线程假设已经跑满了最大线程数,此时子线程拿不到线程,此时发生如上图所示的情况,waitting,类似于死锁?因为子线程都入队列了,得不到执行,线程都在执行父线程

改成自己的线程池即可,不用parallel所在ForkJoinPool线程池

你可能感兴趣的:(java,线程,java,servlet,html)