Class DefaultExecutorProvider

java.lang.Object
dev.langchain4j.internal.DefaultExecutorProvider

public class DefaultExecutorProvider extends Object
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 Details

    • setProvider

      public static void setProvider(ExecutorProvider provider)
      Internal state mutator behind the public ExecutorProvider.set(ExecutorProvider). A programmatically-set provider takes precedence over any ServiceLoader-discovered provider and the built-in default. Pass null to clear it.
    • getProvider

      public static ExecutorProvider getProvider()
      Internal accessor behind the public ExecutorProvider.get().
      Returns:
      the programmatically-set provider, or null if none was set (a ServiceLoader provider or the built-in default may still be in effect).
    • getDefaultExecutor

      public static Executor getDefaultExecutor()
      Returns:
      the resolved Executor (programmatic override → ServiceLoader SPI → built-in virtual-thread default). This is the seam that honors any host-registered ExecutorProvider, including a bare Executor.
    • getDefaultExecutorService

      @Deprecated(since="1.19.0") public static ExecutorService getDefaultExecutorService()
      Deprecated.
      LangChain4j now offloads everything through getDefaultExecutor() (a plain Executor); no internal site needs an ExecutorService anymore. Retained only for backward compatibility with external callers. Prefer getDefaultExecutor().
      Returns:
      an ExecutorService — the registered provider's executor if it is itself an ExecutorService (as most managed pools are), otherwise the built-in default.