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 Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Invoked by the containingBeanFactory
after it has set all bean properties and satisfiedBeanFactoryAware
,ApplicationContextAware
etc.void
destroy()
Invoked by the containingBeanFactory
on destruction of a bean.Return the configuredExecutor
.void
setExecutor
(Executor executor) Configure theExecutor
to use forHttpClient
exchanges.void
setThreadPrefix
(String threadPrefix) Configure the thread prefix to initialize the executor with.
-
Constructor Details
-
JdkHttpClientResourceFactory
public JdkHttpClientResourceFactory()
-
-
Method Details
-
setExecutor
Configure theExecutor
to use forHttpClient
exchanges. The given executor is started and stopped viaInitializingBean
andDisposableBean
.By default, this is set to
Executors.newCachedThreadPool(ThreadFactory)
, which mirrorsHttpClient.Builder.executor(Executor)
.- Parameters:
executor
- the executor to use
-
getExecutor
Return the configuredExecutor
. -
setThreadPrefix
Configure the thread prefix to initialize the executor with. This is used only when aExecutor
instance isn'tprovided
.By default set to "jdk-http".
- Parameters:
threadPrefix
- the thread prefix to use
-
afterPropertiesSet
Description copied from interface:InitializingBean
Invoked by the containingBeanFactory
after it has set all bean properties and satisfiedBeanFactoryAware
,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 interfaceInitializingBean
- Throws:
Exception
- in the event of misconfiguration (such as failure to set an essential property) or if initialization fails for any other reason
-
destroy
Description copied from interface:DisposableBean
Invoked by the containingBeanFactory
on destruction of a bean.- Specified by:
destroy
in interfaceDisposableBean
- Throws:
Exception
- in case of shutdown errors. Exceptions will get logged but not rethrown to allow other beans to release their resources as well.
-