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

查看 Correct handling of background calls in jersey 我知道这是调用异步回调选项的正确方法

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

解决方法

从 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