Class ExecutorInstrumentation

  • All Implemented Interfaces:
    Instrumentation

    @Beta
    public class ExecutorInstrumentation
    extends SimplePerformantInstrumentation
    This instrumentation can be used to control on what thread calls to DataFetchers happen on.

    If your data fetching is inherently IO bound then you could use a IO oriented thread pool for your fetches and transfer control back to a CPU oriented thread pool and allow graphql-java code to run the post-processing of results there.

    An IO oriented thread pool is typically a multiple of Runtime.availableProcessors() while a CPU oriented thread pool is typically no more than Runtime.availableProcessors().

    The instrumentation will use the Instrumentation.instrumentDataFetcher(DataFetcher, InstrumentationFieldFetchParameters, InstrumentationState) method to change your data fetchers, so they are executed on a thread pool dedicated to fetching (if you provide one).

    Once the data fetcher value is returns it will transfer control back to a processing thread pool (if you provide one).

    This code uses CompletableFuture.supplyAsync(Supplier, Executor) and CompletableFuture.thenApplyAsync(Function, Executor) to transfer control between thread pools.