如何安全关闭Webflux上的executorService

问题描述

  1. 我已经在webflux上使用执行程序服务创建了threadPool,但是在完成流量任务之后,我想关闭执行程序服务。

  2. 能否让我知道关闭执行器服务的最安全方法

代码

ExecutorService myPool = Executors.newFixedThreadPool(10); 
try {
        ParallelFlux<ParelleResponceBody> name = Flux.fromIterable(str).parallel(3)
                .runOn(Schedulers.fromExecutorService(myPool)).flatMap(s -> {
                    ParelleResponceBody bodyHolder = new ParelleResponceBody();
                    bodyHolder.setStr(s);
                    return Flux.fromStream(Stream.of(bodyHolder));
                });
            name.subscribe(s -> {
            System.out.println("parallel output : " + s.getstr());
        });
        return name;
    } finally {
        myPool.shutdown();
        System.out.println("checking thread : "+myPool.isShutdown());

    }

例外:

checking thread : true
2020-09-28 12:02:10.614 ERROR 8684 --- [ctor-http-nio-2] a.w.r.e.AbstractErrorWebExceptionHandler : [da6f83ed-1]  500 Server Error for HTTP GET "/flux/parallelFluxexample/"

reactor.core.Exceptions$ReactorRejectedExecutionException: Scheduler unavailable
    at reactor.core.Exceptions.failWithRejected(Exceptions.java:268) ~[reactor-core-3.3.9.RELEASE.jar:3.3.9.RELEASE]
    Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException: 
Error has been observed at the following site(s):
    |_ checkpoint ⇢ Handler com.learnflux.controller.RequestHandler#convertListToMap() [dispatcherHandler]
    |_ checkpoint ⇢ HTTP GET "/flux/parallelFluxexample/" [ExceptionHandlingWebHandler]
Stack trace:
        at reactor.core.Exceptions.failWithRejected(Exceptions.java:268) ~[reactor-core-3.3.9.RELEASE.jar:3.3.9.RELEASE]
        at reactor.core.publisher.Operators.onRejectedExecution(Operators.java:985) ~[reactor-core-3.3.9.RELEASE.jar:3.3.9.RELEASE]
        at reactor.core.publisher.FluxPublishOn$PublishOnSubscriber.trySchedule(FluxPublishOn.java:326) ~[reactor-core-3.3.9.RELEASE.jar:3.3.9.RELEASE]

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)