enterprise-javalisted
Install: claude install-skill ProjAnvil/MindForge
# Enterprise Java — Language Skill
This skill is about the Java language and runtime itself: syntax, the type system, concurrency, virtual threads, the JVM memory model, and the idioms and gotchas that follow from them. It is deliberately framework-neutral. Framework and app-level recipes live in `references/`; see Framework Selection below. Grounded in the Oracle JDK 21 virtual threads guide, JEP 444 (virtual threads), JEP 480/505 (structured concurrency), the Java Memory Model (JSR-133), and the `java.util.concurrent` package docs.
## Gotchas
Each trap is written as symptom -> why -> fix, because the *why* is the part worth remembering.
### 1. Virtual-thread pinning under `synchronized`
- Symptom: throughput collapses when a virtual thread blocks while holding a monitor; adding more virtual threads does not help.
- Why: on JDK 21 a virtual thread inside a `synchronized` block/method that blocks is pinned to its carrier platform thread (JEP 444) — the scheduler cannot unmount it, so the carrier stays occupied for the whole block.
- Fix: replace the monitor with `java.util.concurrent.locks.ReentrantLock`, or move the blocking call out of the synchronized region; never pool virtual threads.
```java
// ReentrantLock lets the virtual thread unmount while waiting.
private final ReentrantLock lock = new ReentrantLock();
lock.lock();
try {
doWork();
} finally {
lock.unlock();
}
```
### 2. Carrier-thread pool starvation
- Symptom: virtual threads stop making progress ev