JVM Concurrency Rules

Provide JVM concurrency rules and best practices for Java and Kotlin.

1|Updated Mar 16, 2026
One-click install
npx skills add https://github.com/iceflower/opencode-agents-and-skills --skill jvm-concurrency-rules
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: JVM Concurrency Rules
Source: https://github.com/iceflower/opencode-agents-and-skills/tree/main/skills/concurrency
Command: npx skills add https://github.com/iceflower/opencode-agents-and-skills --skill jvm-concurrency-rules

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill provides comprehensive guidance on writing safe, efficient, and robust concurrent applications in Java and Kotlin, preventing common bugs like race conditions and deadlocks.

Core Features & Use Cases

  • Thread Safety: Learn principles like immutability, thread-local confinement, and synchronization strategies.
  • Memory Model: Understand happens-before relationships, visibility, and atomicity guarantees.
  • Tool Selection: Choose the right synchronization primitives (locks, atomics, concurrent collections) and executor frameworks.
  • Modern Concurrency: Master CompletableFuture patterns and Kotlin Coroutines, including structured concurrency and dispatcher selection.
  • Virtual Threads: Understand best practices for using Java's virtual threads (Project Loom).
  • Testing & Anti-Patterns: Discover strategies for testing concurrent code and common pitfalls to avoid.
  • Use Case: A developer needs to implement a high-throughput, multi-threaded backend service. This Skill guides them on configuring thread pools, managing shared state safely, and handling asynchronous operations effectively to ensure scalability and prevent crashes.

Quick Start

Review the section on synchronized vs ReentrantLock to understand when to use each.

Frequently Asked Questions about JVM Concurrency Rules

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

FAQPage Schema
How do I ensure thread safety and prevent race conditions in Java?

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

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

Choosing between `synchronized` and `ReentrantLock` for multithreading in Java depends on your requirements for lock interruption, fairness, and timed lock acquisition. Reviewing their specific trade-offs guides optimal synchronization tool selection.

What are the best practices for using Kotlin Coroutines and structured concurrency?

Best practices for Kotlin Coroutines involve leveraging structured concurrency and selecting appropriate dispatchers. Properly managing asynchronous operations and scopes ensures scalable, bug-free concurrent applications without blocking threads.

When should I use Java virtual threads over traditional platform threads?

You should use Java virtual threads over traditional platform threads for high-throughput I/O-bound tasks. Project Loom's virtual threads allow massive scalability by handling blocking operations efficiently without exhausting system resources.

What are common anti-patterns and concurrency bugs to avoid on the JVM?

Common JVM concurrency anti-patterns include deadlocks, improper happens-before visibility, and misusing Executor frameworks. Identifying these bug patterns and applying targeted testing strategies prevents application crashes and data corruption.