mcpField
J
java-concurrency

java-concurrency

github.com/pluginagentmarketplaceDevelopment41466 installsUpdated 42w ago
Repository

About java-concurrency

java-concurrency is a skill covering Java concurrency for developers building thread-safe code, parallel processing, or diagnosing concurrency issues. It spans thread management, synchronization, executors, virtual threads, and CompletableFuture, with tuning and troubleshooting references.

Key features

  1. 01Cover thread lifecycle and interruption
  2. 02Explain locks, synchronization, and atomics
  3. 03Address thread pools and ForkJoinPool
  4. 04Introduce Java 21+ virtual threads
  5. 05Cover CompletableFuture composition and errors

Use cases

  1. 01Implement thread-safe Java code
  2. 02Configure executors for parallel workloads
  3. 03Diagnose deadlocks, races, and starvation
  4. 04Debug thread pools or concurrent tasks

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/pluginagentmarketplace/custom-plugin-java --skill java-concurrency

After installing, type/java-concurrencyin Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

assets/
config.yaml
schema.json
references/
GUIDE.md
PATTERNS.md
scripts/
validate.py

Details

From the project README

Java Concurrency Skill

Master Java concurrency patterns for thread-safe applications.

Overview

This skill covers concurrency from basic threads to virtual threads (Java 21+), including thread pools, synchronization, and CompletableFuture.

When to Use This Skill

Use when you need to:

  • Write thread-safe code
  • Implement parallel processing
  • Use async programming patterns
  • Tune thread pools
  • Debug concurrency issues

Topics Covered

Thread Management
  • Thread lifecycle and states
  • Daemon vs user threads
  • Interrupt handling
Synchronization
  • synchronized, volatile
  • Lock interfaces (ReentrantLock)
  • Atomic operations
Executors
  • ThreadPoolExecutor configuration
  • ForkJoinPool
  • Virtual Threads (Java 21+)
CompletableFuture
  • Async execution
  • Chaining and composition
  • Exception handling

Quick Reference

// 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();
    }
}

Thread Pool Sizing

WorkloadFormulaExample
CPU-boundcores8 threads
I/O-boundcores * (1 + wait/compute)80 threads

Troubleshooting

ProblemCauseSolution
DeadlockCircular lockLock ordering, tryLock
Race conditionMissing syncAdd locks/atomics
Thread starvationUnfair schedulingFair locks
Debug Commands
jstack -l <pid> > threaddump.txt
jcmd <pid> Thread.print

Usage

Skill("java-concurrency")

Comments

Markdown supported