RESTEasy:asyncExecutor在ResteasyClientBuilder中的设置

RESTEasyClientBuilder接受用户定制的「ExecutorService」作为「asyncExecutor」,下面是例子:

/**
 * Executor to use to run AsyncInvoker invocations
 *
 * @param asyncExecutor
 * @param cleanupExecutor true if the Client should close the executor when it is closed
 * @return
 */
@Deprecated
public ResteasyClientBuilder asyncExecutor(ExecutorService asyncExecutor, boolean cleanupExecutor)
{
   this.asyncExecutor = asyncExecutor;
   this.cleanupExecutor = cleanupExecutor;
   return this;
}

这个定制的「asyncExecutor」会在「build()」方法中被传入「ResteasyClient」:

@Override
public ResteasyClient build()
{
   if (HTTPClientVersionCheck.isUseOldHTTPClient() || !HTTPClientVersionCheck.isNewHTTPClientAvailable()) {
	  return buildOld();
   }
   ClientConfiguration config = new ClientConfiguration(getProviderFactory());
   for (Map.Entry<String, Object> entry : properties.entrySet())
   {
	  config.property(entry.getKey(), entry.getValue());
   }

   ExecutorService executor = asyncExecutor;

   if (executor == null)
   {
	  cleanupExecutor = true;
	  executor = Executors.newFixedThreadPool(10);
   }

   ClientHttpEngine engine = httpEngine != null ? httpEngine : new ClientHttpEngineBuilder43().resteasyClientBuilder(this).build();
   return new ResteasyClient(engine, executor, cleanupExecutor, scheduledExecutorService, config);

}

所以说,ResteasyClientasyncExecutor的实际使用者。

此外,我在Apache CXF的ClientBuilder的设计实现当中,并没有看到它像RESTEasy一样使用ExecutorService。

My Github Page: https://github.com/liweinan

Powered by Jekyll and Theme by solid

If you have any question want to ask or find bugs regarding with my blog posts, please report it here:
https://github.com/liweinan/liweinan.github.io/issues