Search code examples
javaasynchronouscallbackjerseyasynccallback

Jersey InvocationCallback Completed: Which thread is used to invoke these methods


I am working on a Async Processing Module and Implemented Jersey Invocation Callback.

My implementation is straight forward and am defining a Completed and Failed methods as mentioned in https://docs.oracle.com/javaee/7/api/javax/ws/rs/client/InvocationCallback.html

and as per https://eclipse-ee4j.github.io/jersey.github.io/documentation/latest/async.html#d0e10417

Looking into Correct handling of background calls in jersey I understand this is the correct way to invoke the async call back options.

However am not able to understand which thread would be used to invoke the callback options? Does Jersey uses forkjoinpool.commonPool to execute these?


Solution

  • From Jersey source code, it creates a thread pool based on the threadpool property

    jersey.config.client.async.threadPoolSize

    passed , defaulting to 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);
    }
    

    In latest version a provider is used https://github.com/eclipse-ee4j/jersey/blob/01c6a32a2064aeff2caa8133472e33affeb8a29a/core-client/src/main/java/org/glassfish/jersey/client/DefaultClientAsyncExecutorProvider.java