java-concurrency
Installation
SKILL.md
Java Concurrency
Priority: P1 (HIGH)
Modern concurrent programming emphasizing Virtual Threads (Loom) and safety.
Implementation Guidelines
- Virtual Threads (Java 21): Use for high-throughput I/O.
Executors.newVirtualThreadPerTaskExecutor(). - Structured Concurrency: Use
StructuredTaskScopeto treat related tasks as a single unit (Scope, Fork, Join). - 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,LongAdderfor simple counters. - Locks: Prefer
ReentrantLock/ReadWriteLockoversynchronizedfor fine-grained control. - Thread Safety: Document
@ThreadSafeor@NotThreadSafe.
Anti-Patterns
- No new Thread(): Use Executors or virtual threads; never create threads manually.
- No Pooling Virtual Threads: Virtual threads are 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.
References
Related skills
More from hoangnguyen0403/agent-skills-standard
skill creator
Standards for creating new High-Density Agent Skills with optimal token economy.
182caveman
>
1java-language
Modern Java 21+ standards including Records, Pattern Matching, and Virtual Threads. Use when working with Java records, sealed classes, switch expressions, text blocks, Optional, or upgrading from older Java versions. (triggers: **/*.java, pom.xml, build.gradle, record, sealed, switch, var, Optional, stream, VirtualThread, instanceof, text block)
1swift swiftui
Standards for State Management, View Lifecycle, and Property Wrappers
1swift tooling
Standards for SPM, Build Configs, and Code Quality
1swift testing
Standards for XCTest, Async Tests, and Test Organization
1