{"id":"e79791e5-befb-4517-bf74-eaadccb15abf","shortId":"QuzN4s","kind":"skill","title":"125-java-concurrency","tagline":"Use when you need to apply Java concurrency best practices — including thread safety fundamentals, ExecutorService thread pool management, concurrent design patterns like Producer-Consumer, asynchronous programming with CompletableFuture, immutability and safe publication, deadlo","description":"# Java rules for Concurrency objects\n\nIdentify and apply Java concurrency best practices to improve thread safety, scalability, and maintainability by using modern `java.util.concurrent` utilities and virtual threads.\n\n**What is covered in this Skill?**\n\n- Thread safety fundamentals: `ConcurrentHashMap`, `AtomicInteger`, `ReentrantLock`, `ReadWriteLock`, Java Memory Model\n- `ExecutorService` thread pool configuration: sizing, keep-alive, bounded queues, rejection policies, graceful shutdown\n- Producer-Consumer and Publish-Subscribe patterns with `BlockingQueue`\n- `CompletableFuture` for non-blocking async composition (`thenApply`/`thenCompose`/`exceptionally`/`orTimeout`)\n- Immutability and safe publication (`volatile`, static initializers)\n- Lock contention and false-sharing performance optimization\n- Virtual threads (`Executors.newVirtualThreadPerTaskExecutor()`) for I/O-bound scalability\n- `ScopedValue` over `ThreadLocal` for immutable cross-task data\n- Cooperative cancellation and `InterruptedException` discipline\n- Backpressure with bounded queues and `CallerRunsPolicy`\n- Deadlock avoidance via global lock ordering and `tryLock` with timeouts\n- ForkJoin/parallel-stream discipline for CPU-bound work\n- Virtual-thread pinning detection (JFR `VirtualThreadPinned`)\n- Thread naming and `UncaughtExceptionHandler` observability\n- Fit-for-purpose primitives: `LongAdder`, `CopyOnWriteArrayList`, `StampedLock`, `Semaphore`, `CountDownLatch`, `Phaser`\n\n**Scope:** The reference is organized by examples (good/bad code patterns) for each core area. Apply recommendations based on applicable examples.\n\n## Constraints\n\nBefore applying any concurrency changes, ensure the project compiles. If compilation fails, stop immediately — compilation failure is a blocking condition. After applying improvements, run full verification.\n\n- **MANDATORY**: Run `./mvnw compile` or `mvn compile` before applying any change\n- **SAFETY**: If compilation fails, stop immediately — compilation failure is a blocking condition that prevents any further processing\n- **VERIFY**: Run `./mvnw clean verify` or `mvn clean verify` after applying improvements\n- **BEFORE APPLYING**: Read the reference for detailed good/bad examples, constraints, and safeguards for each concurrency pattern\n\n## When to use this skill\n\n- Review Java code for concurrency\n\n## Workflow\n\n1. **Compile project before concurrency changes**\n\nRun `./mvnw compile` or `mvn compile` and stop immediately if compilation fails.\n\n2. **Read concurrency reference and analyze hotspots**\n\nRead `references/125-java-concurrency.md` and identify thread-safety, coordination, and throughput issues to address.\n\n3. **Apply concurrency improvements**\n\nImplement suitable concurrency patterns, cancellation discipline, and fit-for-purpose primitives.\n\n4. **Verify with full build**\n\nRun `./mvnw clean verify` or `mvn clean verify` after applying improvements.\n\n## Reference\n\nFor detailed guidance, examples, and constraints, see [references/125-java-concurrency.md](references/125-java-concurrency.md).","tags":["125","java","concurrency","cursor","rules","jabrena","agent-skills","ai-skills","claude","claude-code","claude-code-skills","claude-code-subagents"],"capabilities":["skill","source-jabrena","skill-125-java-concurrency","topic-agent-skills","topic-ai-skills","topic-claude","topic-claude-code","topic-claude-code-skills","topic-claude-code-subagents","topic-claude-skills","topic-cursor-agent","topic-cursor-ai","topic-cursor-skills","topic-cursorai","topic-github-copilot"],"categories":["cursor-rules-java"],"synonyms":[],"warnings":[],"endpointUrl":"https://skills.sh/jabrena/cursor-rules-java/125-java-concurrency","protocol":"skill","transport":"skills-sh","auth":{"type":"none","details":{"cli":"npx skills add jabrena/cursor-rules-java","source_repo":"https://github.com/jabrena/cursor-rules-java","install_from":"skills.sh"}},"qualityScore":"0.631","qualityRationale":"deterministic score 0.63 from registry signals: · indexed on github topic:agent-skills · 362 github stars · SKILL.md body (3,055 chars)","verified":false,"liveness":"unknown","lastLivenessCheck":null,"agentReviews":{"count":0,"score_avg":null,"cost_usd_avg":null,"success_rate":null,"latency_p50_ms":null,"narrative_summary":null,"summary_updated_at":null},"enrichmentModel":"deterministic:skill-github:v1","enrichmentVersion":1,"enrichedAt":"2026-04-26T18:53:41.103Z","embedding":null,"createdAt":"2026-04-18T22:01:57.958Z","updatedAt":"2026-04-26T18:53:41.103Z","lastSeenAt":"2026-04-26T18:53:41.103Z","tsv":"'/mvnw':247,275,319,372 '1':312 '125':1 '2':330 '3':350 '4':366 'address':349 'aliv':89 'analyz':335 'appli':10,46,212,220,240,253,283,286,351,380 'applic':216 'area':211 'async':111 'asynchron':30 'atomicinteg':76 'avoid':159 'backpressur':152 'base':214 'best':13,49 'block':110,237,266 'blockingqueu':105 'bound':90,154,173 'build':370 'callerrunspolici':157 'cancel':148,358 'chang':223,255,317 'clean':276,280,373,377 'code':206,308 'compil':227,229,233,248,251,258,262,313,320,323,328 'completablefutur':33,106 'composit':112 'concurr':4,12,23,42,48,222,299,310,316,332,352,356 'concurrenthashmap':75 'condit':238,267 'configur':85 'constraint':218,294,388 'consum':29,98 'content':125 'cooper':147 'coordin':344 'copyonwritearraylist':193 'core':210 'countdownlatch':196 'cover':68 'cpu':172 'cpu-bound':171 'cross':144 'cross-task':143 'data':146 'deadlo':38 'deadlock':158 'design':24 'detail':291,384 'detect':179 'disciplin':151,169,359 'ensur':224 'exampl':204,217,293,386 'except':115 'executors.newvirtualthreadpertaskexecutor':134 'executorservic':19,82 'fail':230,259,329 'failur':234,263 'fals':128 'false-shar':127 'fit':188,362 'fit-for-purpos':187,361 'forkjoin/parallel-stream':168 'full':243,369 'fundament':18,74 'global':161 'good/bad':205,292 'grace':94 'guidanc':385 'hotspot':336 'i/o-bound':136 'identifi':44,340 'immedi':232,261,326 'immut':34,117,142 'implement':354 'improv':52,241,284,353,381 'includ':15 'initi':123 'interruptedexcept':150 'issu':347 'java':3,11,39,47,79,307 'java-concurr':2 'java.util.concurrent':61 'jfr':180 'keep':88 'keep-al':87 'like':26 'lock':124,162 'longadd':192 'maintain':57 'manag':22 'mandatori':245 'memori':80 'model':81 'modern':60 'mvn':250,279,322,376 'name':183 'need':8 'non':109 'non-block':108 'object':43 'observ':186 'optim':131 'order':163 'organ':202 'ortimeout':116 'pattern':25,103,207,300,357 'perform':130 'phaser':197 'pin':178 'polici':93 'pool':21,84 'practic':14,50 'prevent':269 'primit':191,365 'process':272 'produc':28,97 'producer-consum':27,96 'program':31 'project':226,314 'public':37,120 'publish':101 'publish-subscrib':100 'purpos':190,364 'queue':91,155 'read':287,331,337 'readwritelock':78 'recommend':213 'reentrantlock':77 'refer':200,289,333,382 'references/125-java-concurrency.md':338,390,391 'reject':92 'review':306 'rule':40 'run':242,246,274,318,371 'safe':36,119 'safeguard':296 'safeti':17,54,73,256,343 'scalabl':55,137 'scope':198 'scopedvalu':138 'see':389 'semaphor':195 'share':129 'shutdown':95 'size':86 'skill':71,305 'skill-125-java-concurrency' 'source-jabrena' 'stampedlock':194 'static':122 'stop':231,260,325 'subscrib':102 'suitabl':355 'task':145 'thenappli':113 'thencompos':114 'thread':16,20,53,65,72,83,133,177,182,342 'thread-safeti':341 'threadloc':140 'throughput':346 'timeout':167 'topic-agent-skills' 'topic-ai-skills' 'topic-claude' 'topic-claude-code' 'topic-claude-code-skills' 'topic-claude-code-subagents' 'topic-claude-skills' 'topic-cursor-agent' 'topic-cursor-ai' 'topic-cursor-skills' 'topic-cursorai' 'topic-github-copilot' 'trylock':165 'uncaughtexceptionhandl':185 'use':5,59,303 'util':62 'verif':244 'verifi':273,277,281,367,374,378 'via':160 'virtual':64,132,176 'virtual-thread':175 'virtualthreadpin':181 'volatil':121 'work':174 'workflow':311","prices":[{"id":"232be325-46cf-4ceb-a12b-e66d1515e44b","listingId":"e79791e5-befb-4517-bf74-eaadccb15abf","amountUsd":"0","unit":"free","nativeCurrency":null,"nativeAmount":null,"chain":null,"payTo":null,"paymentMethod":"skill-free","isPrimary":true,"details":{"org":"jabrena","category":"cursor-rules-java","install_from":"skills.sh"},"createdAt":"2026-04-18T22:01:57.958Z"}],"sources":[{"listingId":"e79791e5-befb-4517-bf74-eaadccb15abf","source":"github","sourceId":"jabrena/cursor-rules-java/125-java-concurrency","sourceUrl":"https://github.com/jabrena/cursor-rules-java/tree/main/skills/125-java-concurrency","isPrimary":false,"firstSeenAt":"2026-04-18T22:01:57.958Z","lastSeenAt":"2026-04-26T18:53:41.103Z"}],"details":{"listingId":"e79791e5-befb-4517-bf74-eaadccb15abf","quickStartSnippet":null,"exampleRequest":null,"exampleResponse":null,"schema":null,"openapiUrl":null,"agentsTxtUrl":null,"citations":[],"useCases":[],"bestFor":[],"notFor":[],"kindDetails":{"org":"jabrena","slug":"125-java-concurrency","github":{"repo":"jabrena/cursor-rules-java","stars":362,"topics":["agent-skills","ai-skills","claude","claude-code","claude-code-skills","claude-code-subagents","claude-skills","cursor-agent","cursor-ai","cursor-skills","cursorai","github-copilot","intellij-idea","java","prompting","system-prompts"],"license":"apache-2.0","html_url":"https://github.com/jabrena/cursor-rules-java","pushed_at":"2026-04-26T13:48:39Z","description":"A curated and opinionated collection of Skills and Agents to be used in modern SDLC workflows for Java Enterprise development with your favorite AI Agent harness.","skill_md_sha":"6e721dd0e5ea61d3bcd70be84c6784c1c7e47465","skill_md_path":"skills/125-java-concurrency/SKILL.md","default_branch":"main","skill_tree_url":"https://github.com/jabrena/cursor-rules-java/tree/main/skills/125-java-concurrency"},"layout":"multi","source":"github","category":"cursor-rules-java","frontmatter":{"name":"125-java-concurrency","license":"Apache-2.0","description":"Use when you need to apply Java concurrency best practices — including thread safety fundamentals, ExecutorService thread pool management, concurrent design patterns like Producer-Consumer, asynchronous programming with CompletableFuture, immutability and safe publication, deadlock avoidance, virtual threads, scoped values, backpressure, cancellation discipline, and observability for concurrent systems. This should trigger for requests such as Review Java code for concurrency. Part of cursor-rules-java project"},"skills_sh_url":"https://skills.sh/jabrena/cursor-rules-java/125-java-concurrency"},"updatedAt":"2026-04-26T18:53:41.103Z"}}