CONCURRENCY / NOTES</>↗Concurrency24 Dec 2025
Using ThreadLocal safely is crucial because, while it provides a way to store data that is accessible only by a specific thread, it can easily lead to memory leaks and unexpected behavior in environments that use thread pools (like Spring MVC or Jakarta EE). Here is how to use it safely in your Java applications. […]
CRYPTOGRAPHY / NOTES</>↗Cryptography21 Dec 2025
Atomic variables in java.util.concurrent.atomic are designed for lock-free, thread-safe operations on single variables. They leverage low-level CPU instructions like Compare-And-Swap (CAS) to ensure data consistency without the overhead of synchronized blocks. Here’s a guide on how to use the most common atomic classes. 1. AtomicInteger and AtomicLong These are used for numeric counters or IDs. […]
CONCURRENCY / NOTES</>↗Concurrency20 Dec 2025
In Java, both synchronized and ReentrantLock are used to manage thread safety, but they offer different levels of control and flexibility. 1. synchronized Keyword The synchronized keyword is the built-in mechanism in Java for mutual exclusion. It is simpler to use because the JVM automatically handles acquiring and releasing the lock. Usage: Can be applied […]
CONCURRENCY / NOTES</>↗Concurrency19 Dec 2025
A CountDownLatch is a synchronization aid that allows one or more threads to wait until a set of operations being performed in other threads completes. It’s initialized with a given count, and the await() methods block until the current count reaches zero due to invocations of the countDown() method. Here is a practical guide on […]
CONCURRENCY / NOTES</>↗Concurrency19 Dec 2025
In Java’s concurrency utilities, CyclicBarrier is a synchronization aid that allows a set of threads to all wait for each other to reach a common barrier point. It is called “cyclic” because it can be re-used after the waiting threads are released. Here is a breakdown of how to use it effectively. 1. Basic Concepts […]
CONCURRENCY / NOTES</>↗Concurrency29 Nov 2025
Semaphore is an advanced synchronization mechanism used to control access to a shared resource by multiple threads. It can maintain a set of permits, restricting how many threads can concurrently access a critical section or shared resource. If the permits are exhausted, additional threads will block until permits are released. How to Use Semaphore for […]