Example

Concurrency Executor

Demonstrates how helix-concurrency wraps standard executors so HelixContext and MDC flow across async work. Shows execute(...), submit(...), invokeAll(...), and CompletableFuture.supplyAsync(..., helixExecutorService).
Group
Library
Path
examples/library/concurrency-executor

Overview

Helix Java application that shows how helix-concurrency executors carry HelixContext and logging MDC across async work.

Run this example from the shared examples build:

Run

Run this example from the shared examples build


./gradlew -p examples runExample -Pexample=library/concurrency-executor --init-script "$(pwd)/helix.init.gradle"

What It Shows

  • wrapping a standard ExecutorService with HelixExecutorService
  • using execute(...) with HelixRunnable semantics
  • using submit(...) and invokeAll(...) for context-aware callables
  • using CompletableFuture.supplyAsync(..., helixExecutorService) with the Helix executor
  • propagating a request id and tenant from the calling thread onto worker threads

Example Output

Helix concurrency executor example
execute.runnable=task=execute-runnable tenant=retail-us requestId=req-123
submit.callable=task=submit-callable tenant=retail-us requestId=req-123
invokeAll[0]=task=invoke-all-one tenant=retail-us requestId=req-123
invokeAll[1]=task=invoke-all-two tenant=retail-us requestId=req-123
completableFuture=task=completable-future tenant=retail-us requestId=req-123

Development

Building the Application

Run the following command to build the application:

Command

Building the Application


./gradlew clean build

Testing the Application

Run the following command to run the application tests:

Command

Testing the Application


./gradlew test
./gradlew integration

Running the Example

Run the application and inspect how the same request metadata is visible inside each async task:

Command

Running the Example


./gradlew run