Agentic pattern · Parallelization

Parallelization Workflow

A Spring AI command-line app that sends the same prompt with four different inputs as concurrent LLM calls, then collects the answers in input order.

The fan-out

4 workers → CompletableFuture.allOf → List<String>

Two variations

SectioningSplit a task into independent subtasks and run them at the same time.
VotingRun the same prompt several times to compare answers or take a majority.

Stack

LanguageJava 17
FrameworkSpring Boot 4.1.1 (non-web command-line runner)
AISpring AI 2.1.0-SNAPSHOT, ChatClient
ModelAnthropic Claude (OpenAI and Ollama starters optional)
ConcurrencyFixed thread pool ExecutorService and CompletableFuture
Storage, messaging, cloud, DockerNot used
EndpointsNone. The app runs the analysis once, prints the results and exits.

Run it

export ANTHROPIC_API_KEY=your-key
./mvnw clean package
./mvnw spring-boot:run

Classes

ApplicationSpring Boot entry point. A CommandLineRunner passes four stakeholder groups to the workflow with 4 workers.
ParallelizationlWorkflowSubmits one ChatClient call per input to a thread pool, waits for all of them and returns the answers in input order.