util.concurrent.atomic.AtomicBoolean: practical reference
util.concurrent.atomic.AtomicBoolean: practical reference: AtomicBoolean provides atomic boolean reads, writes, compare-and-set, and memory-effect variants.
CKTIS / Java
Programming syntax, operators and concepts. Find an explanation, explore an example and return to learning.
util.concurrent.atomic.AtomicBoolean: practical reference: AtomicBoolean provides atomic boolean reads, writes, compare-and-set, and memory-effect variants.
AtomicInteger provides atomic operations on a single int value shared between threads. Learn reading, writing, incrementing, and conditional updates, including the limits of atomicity.
AtomicLong holds one long value and provides atomic updates shared by threads. Its incrementAndGet() method increases the value by one and returns the updated result.
AtomicReference<V> provides atomic operations on one reference. Learn how get(), conditional compareAndSet(), and unconditional getAndSet() differ, and why object identity rather than content equality determines whether a conditional replacement succeeds.
LongAccumulator combines long values using a supplied function. It supports concurrent updates, but get() does not provide an atomic snapshot while updates are occurring.
LongAdder maintains a long sum updated by multiple threads. It suits statistics, but sum() does not provide an atomic snapshot, and resetting requires control over concurrent updates.
BlockingQueue<E> supports safe exchange of elements between threads, such as a producer and a consumer. It distinguishes operations that do not wait for space or elements, waiting operations, and timed variants. The example uses an ArrayBlockingQueue with capacity 1.
util.concurrent.Callable: practical reference: Callable<V> is a functional interface for a no-argument task that returns V and may throw Exception.
CompletableFuture<T> represents a future result and lets you connect dependent stages without blocking after every step. Learn transformations, composition, result combination, error recovery, and timeouts in Java SE 21.
util.concurrent.CompletionService: practical reference: CompletionService<V> separates task submission from retrieving Future results in completion order.
util.concurrent.CompletionStage: practical reference: CompletionStage<T> describes a computation stage that performs an action or computes a value when another stage completes.
ConcurrentHashMap lets multiple threads safely use a shared map. Atomic operations for a key do not, however, turn a sequence of calls into a transaction.
Learn ConcurrentLinkedQueue and its add, isEmpty, and poll methods for insertion, empty checks, and safe retrieval.
util.concurrent.CopyOnWriteArrayList: practical reference: CopyOnWriteArrayList<E> is a thread-safe list that copies its entire backing array on every mutation.
CountDownLatch coordinates threads: await() waits until countDown() calls reduce the count to zero. It supports waiting for a group of operations and guarantees visibility of earlier writes.
CyclicBarrier synchronizes a fixed number of participants at successive phase boundaries. Calling await() waits for the others; an optional action combines results before the next phase begins.
java.util.concurrent.Executor accepts Runnable tasks through execute. It separates task submission from execution policy; it guarantees neither a separate thread nor asynchronous execution.
java.util.concurrent.Executors provides factory methods for task executors. Executors.newFixedThreadPool limits the number of active worker threads, but not the queue size. Learn how to retrieve results and close the pool in Java SE 21.
ExecutorService separates task submission from execution management. Learn submit, bulk execution with invokeAll, and shutdown, including the distinction between requesting shutdown and waiting for termination.
util.concurrent.Flow: practical reference: Flow groups Reactive Streams-compatible Publisher, Subscriber, Subscription, and Processor interfaces with demand control.
Future<V> represents an asynchronous task result. Future.get retrieves the result, waiting if necessary, while Future.isDone checks completion, which does not necessarily mean success.
LinkedBlockingQueue is a thread-safe FIFO queue built from linked nodes. It supports an optional capacity bound and operations that wait for space or an element, making it useful for producer–consumer communication.
Condition lets a thread wait for a change to shared state protected by a Lock. Learn await, awaitNanos, signal, and signalAll, and why the state check belongs in a loop.
The java.util.concurrent.locks.Lock interface provides explicit control over locking. Learn the lock()/unlock() pair, the safe try/finally pattern, and an example using ReentrantLock to protect a shared counter.