一键导入
java-concurrency
Master Java concurrency - threads, executors, locks, CompletableFuture, virtual threads
菜单
Master Java concurrency - threads, executors, locks, CompletableFuture, virtual threads
Containerize Java applications - Dockerfile optimization, JVM settings, security
Master core Java programming - syntax, OOP, collections, streams, and exception handling
Master Gradle - Kotlin DSL, task configuration, build optimization, caching
Master JPA/Hibernate - entity design, queries, transactions, performance optimization
Master Maven and Gradle - build configuration, dependencies, plugins, CI/CD
Master Apache Maven - POM configuration, plugins, lifecycle, dependency management
| name | java-concurrency |
| description | Master Java concurrency - threads, executors, locks, CompletableFuture, virtual threads |
| sasmp_version | 1.3.0 |
| version | 3.0.0 |
| bonded_agent | 02-java-advanced |
| bond_type | PRIMARY_BOND |
| allowed-tools | Read, Write, Bash, Glob, Grep |
| parameters | {"concurrency_model":{"type":"string","enum":["threads","executors","virtual_threads","reactive"]},"java_version":{"type":"string","default":"21"}} |
Master Java concurrency patterns for thread-safe applications.
This skill covers concurrency from basic threads to virtual threads (Java 21+), including thread pools, synchronization, and CompletableFuture.
Use when you need to:
// Virtual Threads (Java 21+)
try (var executor = Executors.newVirtualThreadPerTaskExecutor()) {
IntStream.range(0, 10_000).forEach(i ->
executor.submit(() -> processRequest(i)));
}
// CompletableFuture composition
CompletableFuture<Result> result = fetchUser(id)
.thenCompose(user -> fetchOrders(user.id()))
.thenApply(orders -> processOrders(orders))
.exceptionally(ex -> handleError(ex))
.orTimeout(5, TimeUnit.SECONDS);
// Thread pool configuration
ThreadPoolExecutor executor = new ThreadPoolExecutor(
10, 50, 60L, TimeUnit.SECONDS,
new ArrayBlockingQueue<>(1000),
new ThreadPoolExecutor.CallerRunsPolicy()
);
// Lock with timeout
ReentrantLock lock = new ReentrantLock();
if (lock.tryLock(1, TimeUnit.SECONDS)) {
try {
// critical section
} finally {
lock.unlock();
}
}
| Workload | Formula | Example |
|---|---|---|
| CPU-bound | cores | 8 threads |
| I/O-bound | cores * (1 + wait/compute) | 80 threads |
| Problem | Cause | Solution |
|---|---|---|
| Deadlock | Circular lock | Lock ordering, tryLock |
| Race condition | Missing sync | Add locks/atomics |
| Thread starvation | Unfair scheduling | Fair locks |
jstack -l <pid> > threaddump.txt
jcmd <pid> Thread.print
Skill("java-concurrency")