Author name: javaplanet.io

Thread safety utilities and Thread safe collections

Java provides several utilities and collections that help in writing thread-safe code. These utilities and collections are part of the java.util.concurrent package. Thread Safety Utilities Locks and Synchronizers ReentrantLock: Provides a re-entrant mutual exclusion lock with the same basic behaviour and semantics as the implicit monitor lock accessed using synchronized methods and statements but with […]

Thread safety utilities and Thread safe collections Read More »

Locking and Synchronized Collections

Java provides several utilities for managing synchronization in collections to ensure thread safety when multiple threads are accessing or modifying them concurrently. Two primary ways to achieve this are using explicit locking with ReentrantLock and using synchronized collections from the java.util.Collections class. Locking with ReentrantLock ReentrantLock provides explicit control over locking, offering flexibility and capabilities

Locking and Synchronized Collections Read More »

Thread Synchronization

Thread synchronization in Java is essential to ensure that multiple threads can safely access shared resources without causing data corruption or inconsistency. Java provides several mechanisms for thread synchronization: Synchronized Methods and Blocks .Reentrant Locks Volatile Keyword Atomic Variables Wait/Notify Mechanism Semaphore CountDownLatch Synchronized Methods and Blocks Using the synchronized keyword, you can synchronize methods

Thread Synchronization Read More »

Scroll to Top