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
- CustomersPrice sensitive, want better tech, environmental concerns.
- EmployeesJob security worries, need new skills, want clear direction.
- InvestorsExpect growth, want cost control, risk concerns.
- SuppliersCapacity constraints, price pressures, tech transitions.
4 workers → CompletableFuture.allOf → List<String>
Two variations
| Sectioning | Split a task into independent subtasks and run them at the same time. |
|---|---|
| Voting | Run the same prompt several times to compare answers or take a majority. |
Stack
| Language | Java 17 |
|---|---|
| Framework | Spring Boot 4.1.1 (non-web command-line runner) |
| AI | Spring AI 2.1.0-SNAPSHOT, ChatClient |
| Model | Anthropic Claude (OpenAI and Ollama starters optional) |
| Concurrency | Fixed thread pool ExecutorService and CompletableFuture |
| Storage, messaging, cloud, Docker | Not used |
| Endpoints | None. 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
Application | Spring Boot entry point. A CommandLineRunner passes four stakeholder groups to the workflow with 4 workers. |
|---|---|
ParallelizationlWorkflow | Submits one ChatClient call per input to a thread pool, waits for all of them and returns the answers in input order. |