首页 > 解决方案 > Jersey InvocationCallback Completed:哪个线程用于调用这些方法

问题描述

我正在研究异步处理模块并实施 Jersey 调用回调。

我的实现很简单,我定义了一个 Completed 和 Failed 方法,如 https://docs.oracle.com/javaee/7/api/javax/ws/rs/client/InvocationCallback.html中所述

并根据 https://eclipse-ee4j.github.io/jersey.github.io/documentation/latest/async.html#d0e10417

调查球衣中后台调用的正确处理我知道这是调用异步回调选项的正确方法。

但是我无法理解哪个线程将用于调用回调选项?Jersey 是否使用 forkjoinpool.commonPool 来执行这些?

标签: javaasynchronouscallbackjerseyasynccallback

解决方案


从 Jersey 源代码中,它基于 threadpool 属性创建了一个线程池

jersey.config.client.async.threadPoolSize

通过,默认为 0

public ClientRuntime(ClientConfig config, Connector connector, ServiceLocator locator) {
    Builder<ClientRequest> requestingChainBuilder = Stages.chain((Function)locator.createAndInitialize(RequestProcessingInitializationStage.class));
   
    int asyncThreadPoolSize = (Integer)PropertiesHelper.getValue(config.getProperties(), "jersey.config.client.async.threadPoolSize", 0);
    asyncThreadPoolSize = asyncThreadPoolSize < 0 ? 0 : asyncThreadPoolSize;
    this.asyncExecutorsFactory = new ClientAsyncExecutorFactory(locator, asyncThreadPoolSize);
}

在最新版本中,使用了提供程序 https://github.com/eclipse-ee4j/jersey/blob/01c6a32a2064aeff2caa8133472e33affeb8a29a/core-client/src/main/java/org/glassfish/jersey/client/DefaultClientAsyncExecutorProvider.java


推荐阅读