Master Java concurrency - threads, executors, locks, CompletableFuture, virtual threads
Provides Java concurrency patterns for thread-safe code, thread pools, and async programming. Triggers when writing parallel processing, CompletableFuture chains, or debugging deadlocks and thread starvation.
/plugin marketplace add pluginagentmarketplace/custom-plugin-java/plugin install pluginagentmarketplace-java-development-assistant@pluginagentmarketplace/custom-plugin-javaThis skill is limited to using the following tools:
assets/config.yamlassets/schema.jsonreferences/GUIDE.mdreferences/PATTERNS.mdscripts/validate.pyMaster 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")
This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.