java-concurrency-review

Reviews Java concurrent code for thread safety, race conditions, deadlocks, and modern patterns.

Updated Apr 20, 2020
One-click install
npx skills add https://github.com/UnterrainerInformatik/java-rdb-utils --skill java-concurrency-review-unterrainerinformatik
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: java-concurrency-review
Source: https://github.com/UnterrainerInformatik/java-rdb-utils/tree/main/.agents/skills/java-concurrency-review
Command: npx skills add https://github.com/UnterrainerInformatik/java-rdb-utils --skill java-concurrency-review-unterrainerinformatik

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Concurrency bugs in Java are hard to reproduce, hard to test, and hard to debug, often surfacing only in production under load. This Skill catches thread safety issues, race conditions, deadlocks, and misused async patterns during code review before they reach production. ## Core Features & Use Cases - Thread Safety Analysis: Detects race conditions from check-then-act patterns, missing volatile modifiers, non-atomic long/double access, and broken double-checked locking. - Spring @Async Pitfall Detection: Identifies missing @EnableAsync, same-class self-invocation bypassing proxies, non-public async methods, unconfigured default executors, and SecurityContext propagation failures. - Modern Java 21/25 Patterns: Reviews Virtual Threads usage, ScopedValue over ThreadLocal, Structured Concurrency scopes, and CompletableFuture error handling and timeouts. - Use Case: When reviewing a Spring service that uses @Async and CompletableFuture to call external APIs, the Skill flags the default thread-per-task executor as an OOM risk, verifies exception handling with exceptionally() or handle(), and suggests virtual threads for the I/O-bound workload. ## Quick Start Ask the assistant to review your Java class for thread safety and concurrency issues, mentioning any synchronized blocks, @Async methods, or CompletableFuture usage it contains.

Frequently Asked Questions about java-concurrency-review

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I review Java code for thread safety issues?▼

Check shared mutable state for check-then-act race conditions, verify volatile on fields read in loops or used in double-checked locking, and confirm consistent lock ordering to prevent deadlocks. Use ConcurrentHashMap atomic methods like computeIfAbsent instead of manual contains-then-put sequences.

Why is my Spring @Async method running synchronously?▼

@Async runs synchronously when called from within the same class because the self-invocation bypasses the Spring proxy. It also fails silently without @EnableAsync, on non-public methods, or when the method is called before the proxy is initialized.

When should I use virtual threads in Java 21?▼

Use virtual threads for I/O-bound tasks like HTTP calls, database queries, and file operations where you have thousands of concurrent tasks. They provide no benefit for CPU-bound work, which should use platform threads or ForkJoinPool instead.

How do I handle exceptions in CompletableFuture?▼

Attach exceptionally() to recover with a fallback value, or handle() to process both success and failure outcomes. Without these, exceptions from supplyAsync are silently swallowed. Java 9+ also adds orTimeout() and completeOnTimeout() for deadline handling.

Does SecurityContext propagate to @Async methods in Spring?▼

No, SecurityContextHolder is ThreadLocal-bound, so the context is null inside async threads by default. Wrap your executor with DelegatingSecurityContextAsyncTaskExecutor to propagate the security context to async tasks.

What are the limitations of ConcurrentHashMap compute operations?▼

Nested compute calls on the same ConcurrentHashMap can deadlock because the bin is locked during computation. Compound operations like contains-then-put are also non-atomic; use putIfAbsent or computeIfAbsent for atomicity instead.