繁体   English   中英

Spring 启动 java.util.concurrent.ThreadPoolExecutor 大小

[英]Spring Boot java.util.concurrent.ThreadPoolExecutor size

目前我正在测试我的 Spring Boot 应用程序,这是一个带有断路器模式的 rest 服务。 现在我同时用 20 个线程调用我的服务并获得以下日志条目:

Task java.util.concurrent.FutureTask@127adac1[Not completed, task = java.util.concurrent.Executors$RunnableAdapter@74bf28cd[Wrapped task = null]] rejected from java.util.concurrent.ThreadPoolExecutor@19ae13b2[Running, pool size = 10, active threads = 10, queued tasks = 0, completed tasks = 16]

所以我的问题是线程池的最大大小真的是 10,我可以将它设置为不同的东西吗?

我找到了属性server.tomcat.max-threads并将其设置为 10 所有请求都会通过。

编辑

我正在使用 Spring Boot Resttemplate 调用另一个 rest 服务,这会导致问题吗?

    @HystrixCommand(
        commandKey = "callRestService", fallbackMethod = "failCallRestService", ignoreExceptions = DataNotFoundException.class)
    public ResponseEntity<DataAtomsResponse> callRestService(String searchItem, String trackingId)
        throws RestServiceNotAvailableException
    {
        ThreadContext.put("trackingID", trackingId);
        configureRestTemplate();
        LOGGER.info("Received request with trackingId: {}", trackingId);
        Map<String, String> restUrlParams = new HashMap<>();
        restUrlParams.put(REST_URL_PARAMETER, searchItem);
        HttpEntity<String> entity = getRestParameters(trackingId);

        DataAtomsResponse dataAtomsResponse;
        LOGGER.info("Request RestService trackingID: {}", trackingId);
        ResponseEntity<String> dataResponse=
            restTemplate.exchange(config.getRestServiceUrl(), HttpMethod.GET, entity, String.class, restUrlParams);

        if (dataResponse.getStatusCode() == HttpStatus.OK || dataResponse.getStatusCode() == HttpStatus.NOT_FOUND) {
            LOGGER.debug("Transform result from RestService to JSON trackingID: {}", trackingId);
            dataAtomsResponse = dataParser.parse(dataResponse.getBody(), searchItem, trackingId);
            return ResponseEntity.ok(dataAtomsResponse );
        }
        else {
            throw new RestServiceNotAvailableException(dataResponse.getStatusCode().getReasonPhrase());
        }
    }

我没有在任何其他 class 中实现任何 ThreadPoolExecuter。

我发现了问题所在。 Histrix 使用正常的 java ThreadPoolExecutor,最大线程的值设置为 10。这篇https://medium.com/@truongminhtriet96/playing-with-hystrix-thread-pool-c7eebb5b0ddc文章对我帮助很大。 所以我设置了这些配置

hystrix.threadpool.default.maximumSize=32
hystrix.threadpool.default.allowMaximumSizeToDivergeFromCoreSize=true
server.tomcat.max-threads=32```

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM