Class JdkHttpClientResourceFactory

java.lang.Object
org.springframework.http.client.reactive.JdkHttpClientResourceFactory
All Implemented Interfaces:
DisposableBean, InitializingBean

public class JdkHttpClientResourceFactory extends Object implements InitializingBean, DisposableBean
Factory to manage JDK HttpClient resources such as a shared Executor within the lifecycle of a Spring ApplicationContext.

This factory implements InitializingBean and DisposableBean and is expected typically to be declared as a Spring-managed bean.

Since:
6.0
Author:
Rossen Stoyanchev
See Also:
  • Constructor Details

    • JdkHttpClientResourceFactory

      public JdkHttpClientResourceFactory()
  • Method Details

    • setExecutor

      public void setExecutor(@Nullable Executor executor)
      Configure the Executor to use for HttpClient exchanges. The given executor is started and stopped via InitializingBean and DisposableBean.

      By default, this is set to Executors.newCachedThreadPool(ThreadFactory), which mirrors HttpClient.Builder.executor(Executor).

      Parameters:
      executor - the executor to use
    • getExecutor

      @Nullable public Executor getExecutor()
      Return the configured Executor.
    • setThreadPrefix

      public void setThreadPrefix(String threadPrefix)
      Configure the thread prefix to initialize QueuedThreadPool executor with. This is used only when a Executor instance isn't provided.

      By default set to "jetty-http".

      Parameters:
      threadPrefix - the thread prefix to use
    • afterPropertiesSet

      public void afterPropertiesSet() throws Exception
      Description copied from interface: InitializingBean
      Invoked by the containing BeanFactory after it has set all bean properties and satisfied BeanFactoryAware, ApplicationContextAware etc.

      This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set.

      Specified by:
      afterPropertiesSet in interface InitializingBean
      Throws:
      Exception - in the event of misconfiguration (such as failure to set an essential property) or if initialization fails for any other reason
    • destroy

      public void destroy() throws Exception
      Description copied from interface: DisposableBean
      Invoked by the containing BeanFactory on destruction of a bean.
      Specified by:
      destroy in interface DisposableBean
      Throws:
      Exception - in case of shutdown errors. Exceptions will get logged but not rethrown to allow other beans to release their resources as well.