Class DefaultExecutorProvider
java.lang.Object
dev.langchain4j.internal.DefaultExecutorProvider
Resolves the
Executor that LangChain4j uses to offload blocking work and run its asynchronous
continuations. Resolution order: a programmatically-set ExecutorProvider → the first
ExecutorProvider discovered via ServiceLoader → a built-in virtual-thread default.
getDefaultExecutor() returns the resolved executor as-is and backs every offload. The legacy
getDefaultExecutorService() is deprecated (retained only for external back-compat).
This is the single seam a host can use to make LangChain4j's internal thread hops carry its context (tracing,
MDC, security, …): register an ExecutorProvider returning a context-propagating executor. With no
provider registered, the behavior is unchanged — a shared virtual-thread executor is used.
-
Method Summary
Modifier and TypeMethodDescriptionstatic CapturedContextCaptures the context of the calling thread with the registeredExecutorProvider, seeExecutorProvider.captureContext().static Executorstatic ExecutorServiceDeprecated.static ExecutorProviderInternal accessor behind the publicExecutorProvider.get().static voidsetProvider(ExecutorProvider provider) Internal state mutator behind the publicExecutorProvider.set(ExecutorProvider).
-
Method Details
-
setProvider
Internal state mutator behind the publicExecutorProvider.set(ExecutorProvider). A programmatically-set provider takes precedence over anyServiceLoader-discovered provider and the built-in default. Passnullto clear it. -
getProvider
Internal accessor behind the publicExecutorProvider.get().- Returns:
- the programmatically-set provider, or
nullif none was set (aServiceLoaderprovider or the built-in default may still be in effect).
-
getDefaultExecutor
- Returns:
- the resolved
Executor(programmatic override →ServiceLoaderSPI → built-in virtual-thread default). This is the seam that honors any host-registeredExecutorProvider, including a bareExecutor.
-
getDefaultExecutorService
Deprecated.LangChain4j now offloads everything throughgetDefaultExecutor()(a plainExecutor); no internal site needs anExecutorServiceanymore. Retained only for backward compatibility with external callers. PrefergetDefaultExecutor().- Returns:
- an
ExecutorService— the registered provider's executor if it is itself anExecutorService(as most managed pools are), otherwise the built-in default.
-
captureContext
Captures the context of the calling thread with the registeredExecutorProvider, seeExecutorProvider.captureContext().- Returns:
- the captured context, or
nullif there is nothing to capture: noExecutorProvideris registered, or it does not capture context
-
getDefaultExecutor()(a plainExecutor); no internal site needs anExecutorServiceanymore.