goetz-java-concurrency

Provides reference knowledge from Java Concurrency in Practice covering thread safety, executors, and the Java Memory Model.

Updated Jul 28, 2026
One-click install
npx skills add https://github.com/zademy/book-to-skill-zademy --skill goetz-java-concurrency-zademy
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: goetz-java-concurrency
Source: https://github.com/zademy/book-to-skill-zademy/tree/main/.agents/skills/goetz-java-concurrency
Command: npx skills add https://github.com/zademy/book-to-skill-zademy --skill goetz-java-concurrency-zademy

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Java concurrency bugs like race conditions, deadlocks, and visibility failures are hard to diagnose and fix without a solid mental model. This Skill gives you instant access to the frameworks, patterns, and decision rules from Brian Goetz's "Java Concurrency in Practice" so you can design, review, and debug concurrent Java code correctly. ## Core Features & Use Cases - Core Frameworks Reference: Covers thread safety, safe publication, immutability, delegation, the Executor framework, cooperative cancellation, lock ordering, Amdahl's Law, and the Java Memory Model. - Chapter and Topic Index: Look up any of the book's 16 chapters or jump directly to indexed topics like ConcurrentHashMap, thread pool sizing, or the Memoizer pattern. - Cheatsheet, Glossary, and Patterns: Quick decision tables (which synchronizer to use), definitions of key terms, and reusable design patterns with trade-offs. - Use Case: You are reviewing code that uses if (!map.containsKey(k)) map.put(k, v) on a synchronized map. Ask about put-if-absent races and get the explanation plus the fix using ConcurrentHashMap.putIfAbsent. ## Quick Start Ask the agent to explain safe publication and the four safe publication idioms from the Goetz concurrency skill.

Frequently Asked Questions about goetz-java-concurrency

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I make a Java class thread-safe?▼

Thread safety is about managing shared mutable state: either confine the state to one thread, make it immutable, or synchronize every access with the same lock. Identify the class's state variables and invariants first, then document a synchronization policy guarding each variable.

When should I use synchronized vs ReentrantLock in Java?▼

Use synchronized by default; choose ReentrantLock only when you need timed, polled, or interruptible lock acquisition, fair queuing, or non-block-structured locking. Fair locks are roughly an order of magnitude slower under contention, so default to nonfair.

How do I size a Java thread pool correctly?▼

Use the formula N_threads = N_cpu x U_cpu x (1 + Wait/Compute) for mixed workloads, N_cpu + 1 for compute-bound tasks, and cap the pool at the resource limit for resource-bound work. Always bound queues and pick a saturation policy like caller-runs.

Why does my Java program see stale values without synchronization?▼

Without synchronization, the JVM may reorder operations and cache values per-thread, so readers can see stale or out-of-order data. Locking guarantees both atomicity and visibility; volatile guarantees visibility only and suits simple status flags.

Does this skill cover virtual threads or structured concurrency?▼

No. The skill covers the book's content, which is Java 6-era java.util.concurrent, though the core principles remain current. For virtual threads, structured concurrency, or reactive streams, consult other resources.