Class ContextTrackingExecutor

  • All Implemented Interfaces:
    Executor, ExecutorService

    public class ContextTrackingExecutor
    extends ThreadPoolExecutor
    A ThreadPoolExecutor that upon task execution automatically updates which thread runs within which ServerSideContext using supplied trackers.

    Instances usually correspond 1-1 with some type of blocking or time consuming operations, such as CPU/GPU intensive calculations or blocking network communication with some resource.
    In case of network operations, a given threadPool size should usually correspond to the pool size of the connections to the given resource.
    In case of CPU/GPU intensive operations, it should usually correspond to the number of given cores available to the process.

    Instances are usually created at app startup, stored on static vars and/or configured for injection using

     bind(ContextTrackingExecutor.class)
        .annotatedWith(Names.named("someOpTypeExecutor"))
        .toInstance(...)
    and injected with
    @Named("someOpTypeExecutor") ContextTrackingExecutor someOpTypeExecutor

    If multiple threads run within the same context (for example by using invokeAll(Collection)), then the attributes they access must be thread-safe or properly synchronized.