java-concurrency-guidelines

Guide Java concurrency decisions for synchronization primitives and memory visibility.

Updated Dec 23, 2025
One-click install
npx skills add https://github.com/BNTang/Sa-Token-Demo --skill java-concurrency-guidelines
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: java-concurrency-guidelines
Source: https://github.com/BNTang/Sa-Token-Demo/tree/main/.claude/skills/java-concurrency-guidelines
Command: npx skills add https://github.com/BNTang/Sa-Token-Demo --skill java-concurrency-guidelines

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Java concurrency can be tricky; this Skill provides a structured set of guidelines to help developers write correct and efficient multithreaded code, covering locks, memory models, and threading patterns.

Core Features & Use Cases

  • Clear decision rules for selecting synchronization primitives (synchronized vs ReentrantLock vs ReadWriteLock) based on workload.
  • Memory visibility and ordering guidance (volatile, final, happens-before) for stable data sharing.
  • Practical patterns for code review, architecture decisions, and interview prep with real-world examples.

Quick Start

Review a sample multi-threaded module and apply the decision checklist to determine the appropriate synchronization strategy.

Frequently Asked Questions about java-concurrency-guidelines

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

FAQPage Schema
How do I choose between synchronized and ReentrantLock for Java multithreading?

To choose between synchronized and ReentrantLock for Java multithreading, apply the decision checklist based on workload. ReentrantLock is selected for advanced features like interruptible lock acquisition, whereas synchronized is preferred for simple, uncontended locking.

What is the Java memory model and how does volatile affect memory visibility?

The Java memory model defines how threads interact with memory, and volatile ensures memory visibility by establishing happens-before relationships. This prevents threads from reading stale, cached values from CPU registers or local caches.

How do I review multithreaded code for thread safety and correct locking strategies?

To review multithreaded code for thread safety, apply the structured guidelines to verify correct synchronization primitives, memory visibility, and ordering. This enforces core rules for stable data sharing and validates lock-free or lock-based patterns.

When should I use ReadWriteLock instead of ReentrantLock in Java concurrency?

Use ReadWriteLock instead of ReentrantLock in Java concurrency when your workload involves many concurrent read operations and few writes. This locking strategy allows multiple threads to read simultaneously while blocking writes.

Does volatile guarantee thread safety for compound actions in Java?

Volatile does not guarantee thread safety for compound actions in Java. It only ensures memory visibility and ordering for single read or write operations, requiring lock-free patterns or synchronized blocks for atomic compound actions.