java-concurrency by pluginagentmarketplace/custom-plugin-java
npx skills add https://github.com/pluginagentmarketplace/custom-plugin-java --skill java-concurrency掌握 Java 并发模式,构建线程安全的应用程序。
本技能涵盖从基础线程到虚拟线程(Java 21+)的并发知识,包括线程池、同步机制和 CompletableFuture。
当您需要时使用此技能:
// 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();
}
}
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
| 工作负载类型 | 计算公式 | 示例 |
|---|---|---|
| CPU 密集型 | 核心数 | 8 个线程 |
| I/O 密集型 | 核心数 * (1 + 等待时间/计算时间) | 80 个线程 |
| 问题 | 原因 | 解决方案 |
|---|---|---|
| 死锁 | 循环锁 | 锁顺序,tryLock |
| 竞态条件 | 缺少同步 | 添加锁/原子操作 |
| 线程饥饿 | 不公平调度 | 公平锁 |
jstack -l <pid> > threaddump.txt
jcmd <pid> Thread.print
Skill("java-concurrency")
每周安装量
219
代码仓库
GitHub 星标数
27
首次出现
2026年1月21日
安全审计
安装于
opencode184
gemini-cli176
codex173
github-copilot162
cursor135
amp133
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")
Weekly Installs
219
Repository
GitHub Stars
27
First Seen
Jan 21, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode184
gemini-cli176
codex173
github-copilot162
cursor135
amp133
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
109,600 周安装