<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Concurrency on Java &amp; Software Architecture Knowledge Hub</title><link>https://samirsahoo.github.io/design-patterns-hub/tags/concurrency/</link><description>Recent content in Concurrency on Java &amp; Software Architecture Knowledge Hub</description><generator>Hugo</generator><language>en-US</language><copyright>© 2026 Samir Kumar Sahoo (https://github.com/samirsahoo). All rights reserved.</copyright><atom:link href="https://samirsahoo.github.io/design-patterns-hub/tags/concurrency/index.xml" rel="self" type="application/rss+xml"/><item><title>The Java Memory Model and Happens-Before</title><link>https://samirsahoo.github.io/design-patterns-hub/java/advanced/java-memory-model/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://samirsahoo.github.io/design-patterns-hub/java/advanced/java-memory-model/</guid><description>&lt;h2 id="simple-definition"&gt;Simple definition&lt;a class="heading-anchor" href="#simple-definition" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;The &lt;strong&gt;Java Memory Model (JMM)&lt;/strong&gt;, defined in chapter 17 of the Java Language Specification, specifies &lt;strong&gt;when a write made by one thread is guaranteed to be visible to another&lt;/strong&gt;. It defines a &lt;strong&gt;happens-before&lt;/strong&gt; relation: if action A happens-before action B, then B sees A&amp;rsquo;s effects.&lt;/p&gt;</description></item><item><title>The Java Concurrency API: Executors, CompletableFuture, Locks and Concurrent Collections</title><link>https://samirsahoo.github.io/design-patterns-hub/java/advanced/concurrency-api/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://samirsahoo.github.io/design-patterns-hub/java/advanced/concurrency-api/</guid><description>&lt;h2 id="simple-definition"&gt;Simple definition&lt;a class="heading-anchor" href="#simple-definition" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;&lt;code&gt;java.util.concurrent&lt;/code&gt; provides &lt;strong&gt;higher-level building blocks&lt;/strong&gt; for running work in parallel and coordinating threads safely:&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;strong&gt;executors&lt;/strong&gt; run tasks&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;futures&lt;/strong&gt; represent results that arrive later&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;locks and atomics&lt;/strong&gt; protect shared state&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;concurrent collections&lt;/strong&gt; are safe to share between threads.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;h2 id="the-problem"&gt;The problem&lt;a class="heading-anchor" href="#the-problem" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;Creating raw &lt;code&gt;Thread&lt;/code&gt;s per task does not scale (platform threads are expensive OS threads). Hand-written &lt;code&gt;wait&lt;/code&gt;/&lt;code&gt;notify&lt;/code&gt; code is notoriously buggy. Sharing a plain &lt;code&gt;HashMap&lt;/code&gt; between threads corrupts it. The concurrency API gives tested abstractions, so you rarely touch low-level primitives.&lt;/p&gt;</description></item><item><title>Singleton Pattern</title><link>https://samirsahoo.github.io/design-patterns-hub/design-patterns/creational/singleton/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://samirsahoo.github.io/design-patterns-hub/design-patterns/creational/singleton/</guid><description>&lt;h2 id="simple-definition"&gt;Simple definition&lt;a class="heading-anchor" href="#simple-definition" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;The &lt;strong&gt;Singleton&lt;/strong&gt; pattern makes sure a class has &lt;strong&gt;exactly one instance&lt;/strong&gt; in a process and gives everyone a way to reach it.&lt;/p&gt;&#10;&lt;p&gt;GoF intent: &lt;em&gt;&amp;ldquo;Ensure a class only has one instance, and provide a global point of access to it.&amp;rdquo;&lt;/em&gt;&lt;/p&gt;</description></item><item><title>Virtual Threads, Structured Concurrency and Scoped Values</title><link>https://samirsahoo.github.io/design-patterns-hub/java/advanced/virtual-threads-and-structured-concurrency/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://samirsahoo.github.io/design-patterns-hub/java/advanced/virtual-threads-and-structured-concurrency/</guid><description>&lt;h2 id="simple-definition"&gt;Simple definition&lt;a class="heading-anchor" href="#simple-definition" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;A &lt;strong&gt;virtual thread&lt;/strong&gt; (Java 21, Project Loom) is a &lt;code&gt;Thread&lt;/code&gt; managed by the JVM rather than the operating system. It is so cheap that you can create &lt;strong&gt;millions&lt;/strong&gt;, one per request or task. When it blocks on I/O, the JVM &lt;strong&gt;parks&lt;/strong&gt; it and frees the underlying OS thread for other work.&lt;/p&gt;</description></item><item><title>Transactions and Isolation Levels: ACID, Anomalies and Serializability</title><link>https://samirsahoo.github.io/design-patterns-hub/data-systems/transactions-and-isolation/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://samirsahoo.github.io/design-patterns-hub/data-systems/transactions-and-isolation/</guid><description>&lt;h2 id="simple-definition"&gt;Simple definition&lt;a class="heading-anchor" href="#simple-definition" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;A &lt;strong&gt;transaction&lt;/strong&gt; groups several reads and writes into one logical unit: either all of them take effect (&lt;strong&gt;commit&lt;/strong&gt;) or none do (&lt;strong&gt;abort&lt;/strong&gt;, rollback). Transactions let applications ignore whole classes of problems — crashes halfway through, concurrent clients interfering — because the database handles them.&lt;/p&gt;</description></item><item><title>Designing Concurrent Objects: Safety, Liveness and Locking Strategies</title><link>https://samirsahoo.github.io/design-patterns-hub/java/advanced/concurrent-object-design/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://samirsahoo.github.io/design-patterns-hub/java/advanced/concurrent-object-design/</guid><description>&lt;h2 id="simple-definition"&gt;Simple definition&lt;a class="heading-anchor" href="#simple-definition" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;A &lt;strong&gt;thread-safe&lt;/strong&gt; class behaves correctly when its methods are called from several threads at the same time, without callers needing extra synchronization. Designing one means balancing four forces that Doug Lea describes in &lt;em&gt;Concurrent Programming in Java&lt;/em&gt;:&lt;/p&gt;</description></item><item><title>State-Dependent Actions: Balking, Guarded Suspension and Timeouts</title><link>https://samirsahoo.github.io/design-patterns-hub/java/advanced/state-dependent-actions/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://samirsahoo.github.io/design-patterns-hub/java/advanced/state-dependent-actions/</guid><description>&lt;h2 id="simple-definition"&gt;Simple definition&lt;a class="heading-anchor" href="#simple-definition" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;A &lt;strong&gt;state-dependent action&lt;/strong&gt; is an operation that only makes sense when an object is in a certain state: you cannot take an item from an empty queue, withdraw from an empty account, or start an engine that is already running. In a single-threaded program, the wrong state is an error. In a concurrent program, the state might become right &lt;strong&gt;if you wait&lt;/strong&gt;, because another thread may change it.&lt;/p&gt;</description></item><item><title>Concurrency Design Patterns: Messages, Worker Threads, Futures, Cancellation and Pipelines</title><link>https://samirsahoo.github.io/design-patterns-hub/java/advanced/concurrency-design-patterns/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://samirsahoo.github.io/design-patterns-hub/java/advanced/concurrency-design-patterns/</guid><description>&lt;h2 id="simple-definition"&gt;Simple definition&lt;a class="heading-anchor" href="#simple-definition" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;Once objects are safe to share (see &lt;a href="https://samirsahoo.github.io/design-patterns-hub/java/advanced/concurrent-object-design/"&gt;Designing concurrent objects&lt;/a&gt;), the next question is &lt;strong&gt;how work gets onto threads&lt;/strong&gt; and how results and failures come back. Doug Lea&amp;rsquo;s &lt;em&gt;Concurrent Programming in Java&lt;/em&gt; catalogues the recurring answers. Most now have direct support in &lt;code&gt;java.util.concurrent&lt;/code&gt;, so this page names each pattern, explains the forces behind it, and shows the modern API.&lt;/p&gt;</description></item></channel></rss>