Loading…
Loading…
Topic
Articles and problems tagged Concurrency.
Concurrent collections and threading problems for the OCP 21 exam: ConcurrentHashMap, CopyOnWriteArrayList, skip-list and blocking queue classes, synchronized wrappers, ConcurrentModificationException, then deadlock, starvation, livelock and race conditions with fixes.
The Lock framework and coordination tools for the OCP 21 exam: ReentrantLock with lock, unlock and tryLock, fairness, hold counts, IllegalMonitorStateException, ReentrantReadWriteLock, CyclicBarrier with barrier actions, plus CountDownLatch and Semaphore.
Thread safety for the OCP 21 exam: why ++ loses updates, what volatile does and doesn't do, AtomicInteger and the other atomic classes, synchronized blocks and methods, which object is the lock, reentrancy and the BLOCKED state.
The Concurrency API for the OCP 21 exam: Executors factory methods, execute versus submit, Callable and Future, get with timeouts, ExecutionException, cancel, invokeAll and invokeAny, shutdown, shutdownNow and close, ScheduledExecutorService and virtual-thread executors.
Threads for the OCP 21 exam: processes, tasks and shared memory, platform versus virtual threads and carrier threads, creating threads with Thread.ofPlatform, Thread.ofVirtual and the constructor, start versus run, join, priorities, daemon threads, the six thread states and interrupting.
Handling exceptions for the OCP 21 exam: try and catch syntax, ordering chained catch blocks, unreachable catches, multi-catch rules, finally execution order, return values and finally, exceptions thrown from finally, System.exit, wrapping causes and rethrowing.
Java's data types for the OCP 21 exam: the eight primitives and their ranges, numeric literals in four bases, underscore rules, primitives versus references, wrapper classes with valueOf and parseXxx, and text blocks with incidental whitespace and escapes.
The OCP Java 21 basics: what the JDK, javac, java and the JVM do, how a class and a source file are structured, the three comment styles, every legal form of main(), command-line arguments, single-file launching and Java 25's compact source files.
Cancel blocked network operations and secure connections: why interrupt doesn't unblock a Socket on a platform thread, SocketChannel and ClosedByInterruptException, virtual threads, then TLS with SSLSocket and SSLServerSocket, certificates, keystores, trust stores and SSLContext.
Write TCP servers in Java: ServerSocket, binding and backlog, the accept loop, an echo server, serving many clients concurrently with one virtual thread per connection, half-closing a connection with shutdownOutput, and shutting a server down cleanly.
Coordinate processes that share a file with Java's FileChannel.lock and tryLock: exclusive and shared locks, locking regions, releasing with try-with-resources, a locked read-modify-write update, OverlappingFileLockException, and the platform caveats such as advisory locks on Linux.
Use Java parallel streams correctly: parallelStream and parallel, why shared mutable state causes race conditions, encounter order and unordered(), groupingByConcurrent, when parallelism pays off, the common ForkJoinPool, running in a custom pool, and random numbers in parallel.
Use Java 24's stream gatherers, the extension point for intermediate operations. Group elements with windowFixed and windowSliding, compare neighbors, fold and scan sequentially, run blocking calls on virtual threads with mapConcurrent, and chain gatherers with andThen.
Share data between Java threads without bugs: memory visibility and volatile, final fields, AtomicInteger and compareAndSet, LongAdder, lazy holder initialization, safe publication, lock-ordering deadlocks, ThreadLocal, InheritableThreadLocal and ScopedValue.
Make threads wait for a condition safely with Condition.await and signalAll, then learn Java's built-in alternative: synchronized methods and blocks, intrinsic locks, wait and notifyAll, choosing lock objects, client-side locking, and the monitor concept.
Why unsynchronized threads corrupt shared data, shown step by step with a lost-update race, and how to fix it with ReentrantLock: the lock/try/finally idiom, critical sections, reentrancy and hold counts, tryLock, fair locks, and the mistakes that cause bugs.
Run tasks that return results with Callable and Future, then let an ExecutorService manage threads: fixed, cached and single-thread pools, virtual-thread-per-task executors, get with timeouts, cancellation, Future.state and resultNow, closing executors, and throttling with semaphores.
Everything about Java thread properties: virtual threads and carrier threads (Java 21), cooperative cancellation with interrupt, handling InterruptedException correctly, daemon threads, names and IDs, uncaught exception handlers, priorities, and thread builders and factories.
The Java thread life cycle explained: the six Thread.State values, what moves a thread between NEW, RUNNABLE, BLOCKED, WAITING, TIMED_WAITING and TERMINATED, how platform and virtual threads are scheduled, join with timeouts, and why stop, suspend and resume are gone.
Start your first Java threads: what threads are compared with processes, putting a task in a Runnable, starting it with Thread.start, waiting with join, why calling run() is a bug, Java 21 thread builders, and why you shouldn't subclass Thread. Includes a two-thread bank transfer example.