Java 21 virtual Thread error RejectedExecutionException: Thread limit exceeded replacing blocked worker

103 views Asked by At

My code has a lot of number of network IO operations, I IO operations at a time when using a new virtual Thread, program error tip RejectedExecutionException: Thread limit exceeded replacing blocked worker. I understand that the virtual thread should be independent of the ForkJoinPool thread number and can be created at will. Why does the problem of insufficient number of threads occur ? this is code

Thread.startVirtualThread(() -> minioUtil.uploadAndDelete(originPath, targetPath, bucketName));

this is error

java.util.concurrent.RejectedExecutionException: Thread limit exceeded replacing blocked worker
    at simple.other.minio.MinioUtil.uploadAndDelete(MinioUtil.java:120)
    at simple.service.uploadFileService.UploadFileService.lambda$uploadMailToMinio$0(UploadFileService.java:54)
    at java.base/java.lang.VirtualThread.run(Unknown Source)
Caused by: java.util.concurrent.RejectedExecutionException: Thread limit exceeded replacing blocked worker
    at java.base/java.util.concurrent.ForkJoinPool.tryCompensate(Unknown Source)
    at java.base/java.util.concurrent.ForkJoinPool.compensatedBlock(Unknown Source)
    at java.base/java.util.concurrent.ForkJoinPool.managedBlock(Unknown Source)
    at java.base/java.util.concurrent.CompletableFuture.waitingGet(Unknown Source)
    at java.base/java.util.concurrent.CompletableFuture.get(Unknown Source)
    at io.minio.S3Base.uploadParts(S3Base.java:2704)
    at io.minio.S3Base.lambda$putMultipartObjectAsync$23(S3Base.java:2735)
    at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(Unknown Source)
    at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.exec(Unknown Source)
    at java.base/java.util.concurrent.ForkJoinTask.doExec(Unknown Source)
    at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(Unknown Source)
    at java.base/java.util.concurrent.ForkJoinPool.scan(Unknown Source)
    at java.base/java.util.concurrent.ForkJoinPool.runWorker(Unknown Source)
    at java.base/java.util.concurrent.ForkJoinWorkerThread.run(Unknown Source)

I want the virtual thread that is doing the IO operation to be automatically suspended without occupying the ForkJoinPool's platform thread resources until the IO operation is finished

0

There are 0 answers