Synchronous Blocking to Async / Reactive Modernization
Convert blocking I/O code into non-blocking async/await, reactive streams, or virtual threads.
Interactive Prompt Playground
{{BLOCKING_CODE}}{{ASYNC_PARADIGM}}You are a High-Throughput Concurrency and Async Systems Engineer.
Modernize this blocking synchronous code into high-performance asynchronous / reactive architecture:
Blocking Code:
```
public List<EnrichedUser> enrichUsers(List<String> userIds) {
List<EnrichedUser> results = new ArrayList<>();
for (String id : userIds) {
User user = restTemplate.getForObject("https://api.users.com/" + id, User.class);
CreditScore score = restTemplate.getForObject("https://api.credit.com/" + id, CreditScore.class);
results.add(new EnrichedUser(user, score));
}
return results;
}
```
Target Platform & Paradigm: Java 21 Virtual Threads & StructuredTaskScope
Perform a comprehensive concurrency refactoring:
1. **Blocking Call Identification**:
- Pinpoint all blocking operations (synchronous network I/O, file access, thread sleep, synchronous DB calls).
2. **Concurrency & Backpressure Strategy**:
- Design concurrency limits (pools / semaphores) to avoid exhausting downstream systems.
- Handle timeout propagation and structured concurrency cancellation tokens.
3. **Exception & Cancellation Handling**:
- Ensure errors in parallel branches are cleanly aggregated without dangling orphaned threads/promises.
4. **Refactored Async Implementation**:
- Provide the complete, robust non-blocking code.How to Use This Prompt
- Paste your sequential blocking loop or I/O handler.
- Specify your target async engine (Virtual Threads, WebFlux, Promise.all).
- Get a structured concurrent implementation with error cancellation.
Engineering Tips & Best Practices
- In Java 21+, prefer Virtual Threads over complex reactive streams unless you strictly require reactive operators.
What This Prompt Inspects
Key failure modes, design principles, and quality standards evaluated during execution.
Thread Pool Starvation
Eliminates blocking thread waits that exhaust worker thread pools.
Structured Concurrency
Cancels sibling tasks automatically if one parallel subtask fails.
Rate Limiting & Throttling
Bounds parallel fan-out with semaphores to protect downstream APIs.
SprintKit Workflow Integrations
Complementary interactive tools and workflows across SprintKit to accelerate your engineering process.
Related Prompts
Explore related developer prompts in this workflow domain.
API Performance Regression & N+1 Query Debugger
Identify slow database queries, serialization bottlenecks, and memory churn in sluggish API endpoints.
Node.js & V8 Memory Leak / CPU Spike Investigator
Analyze heap snapshots, unclosed event listeners, and runaway closures causing Node.js OOM crashes.
Legacy Code Safe Refactoring with Characterization Tests
Safely modernize fragile legacy codebases using Martin Fowler refactoring patterns and golden master tests.