Agent-skills-standard java-concurrency
Implement modern concurrency with Virtual Threads and Structured Concurrency in Java. Use when implementing Java Virtual Threads (Java 21), Structured Concurrency with StructuredTaskScope, CompletableFuture pipelines, or debugging race conditions. (triggers: **/*.java, Thread, Executor, synchronized, lock, CompletableFuture, StructuredTaskScope, VirtualThread, AtomicInteger, async, race condition)
install
source · Clone the upstream repo
git clone https://github.com/HoangNguyen0403/agent-skills-standard
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/HoangNguyen0403/agent-skills-standard "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/java/java-concurrency" ~/.claude/skills/hoangnguyen0403-agent-skills-standard-java-concurrency && rm -rf "$T"
manifest:
skills/java/java-concurrency/SKILL.mdsource content
Java Concurrency
Priority: P1 (HIGH)
Implementation Guidelines
- Virtual Threads (Java 21): Use for high-throughput I/O.
.Executors.newVirtualThreadPerTaskExecutor() - Structured Concurrency: Use
to treat related tasks as single unit (Scope, Fork, Join).StructuredTaskScope - Immutability: Share immutable data between threads to avoid race conditions.
- CompletableFuture: Use for composing async pipelines (if not using Virtual Threads).
- Atomic Variables: Use
,AtomicInteger
for simple counters.LongAdder - Locks: Prefer
/ReentrantLock
overReadWriteLock
for fine-grained control.synchronized - Thread Safety: Document
or@ThreadSafe
.@NotThreadSafe
Anti-Patterns
- No new Thread(): Use Executors or virtual threads; never create threads manually.
- No Pooling Virtual Threads: Virtual threads cheap; never pool them.
- No Blocking in synchronized: Pins carrier thread (Loom pitfall); use ReentrantLock instead.
- No Shared Mutable State: Share only immutable data between threads.
- No Thread.stop/suspend: Deprecated; use interruption or cancellation instead.