【问题标题】:Jersey InvocationCallback Completed: Which thread is used to invoke these methodsJersey InvocationCallback Completed:哪个线程用于调用这些方法
【发布时间】:2021-06-09 00:38:16
【问题描述】:

我正在开发一个异步处理模块并实现 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 来执行这些?

【问题讨论】:

    标签: java asynchronous callback jersey asynccallback


    【解决方案1】:

    来自 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

    【讨论】:

      猜你喜欢
      • 2016-01-28
      • 1970-01-01
      • 1970-01-01
      • 2011-05-10
      • 1970-01-01
      • 2012-01-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多