Java

Java RMI

Java RMI Introduction Java Remote Method Invocation (RMI) enables remote communication between programs running across different Java Virtual Machines (JVM). RMI essentially allows an object running in one JVM to invoke a method on another object running in a different JVM. Java RMI provides the ability to write distributed objects in a simple and secure …

Java RMI Read More »

Java Messaging Service (JMS) using ActiveMQ

Java Messaging Service (JMS) Introduction Java Messaging Service (JMS) provides a mechanism for applications to create, send and receive messages using reliable, asynchronous and loosely coupled communication. JMS is defined as part of the Java Enterprise Edition. JMS supports two messaging models, point-to-point model and the publish subscribe model. In the point to point messaging …

Java Messaging Service (JMS) using ActiveMQ Read More »

Java ReentrantReadWriteLock

ReentrantReadWriteLock Introduction A read-write lock provides greater level of concurrency than a mutual exclusion lock when working with shared data. Read-write locks allows simultaneous read only operations by multiple threads whereas a write operation can be performed by only one thread. Read-write locks provide increased level of concurrency and typically results in better performance if …

Java ReentrantReadWriteLock Read More »

Java ReentrantLock

ReentrantLock Introduction Lock provides a tool to control access to a shared resource in a multi-threaded environment. A lock provides access to only one thread at a time to the shared resource. Using synchronized methods and statements provides access to an implicit lock for an object. However in certain scenarios we might need access explicitly …

Java ReentrantLock Read More »

Java Atomic Variables

Atomic Operations Introduction Traditional multi-threading approaches use locks to protect shared resources.  Synchronization objects like Semaphores provide mechanisms for the programmer to write code that doesn’t modify a shared resource concurrently. The synchronization approaches block other threads when one of the thread is modifying a shared resource. Obviously blocked threads are not doing meaningful work …

Java Atomic Variables Read More »

Java Exchanger

Exchanger Introduction Exchanger is a synchronization point in which threads can pair and exchange objects. Exchanger simplifies data exchange between two threads. Exchanger waits till two threads reach the synchronization point and then exchanges the data provided by the threads. Java Exchanger Class Java support Exchanger synchronization object. Exchanger is a generic class and support …

Java Exchanger Read More »

Java CyclicBarrier

CyclicBarrier Introduction CyclicBarrier is a synchronization object that will release when a given number of threads are waiting on it. CyclicBarrier is initialized with a count that indicates the number of threads that must wait on this barrier. CyclicBarrier is useful in applications where threads needs to wait for each other.  Java CyclicBarrier Class Java …

Java CyclicBarrier Read More »

Java CountDownLatch

CountDownLatch Introduction CountDownLatch is a synchronization object that allows a thread to wait till certain events occur in other threads. We can make the current thread to wait until few dependent threads have completed their operation. CountDownLatch starts with a initial count. Thread that needs to wait, blocks until the count reaches to zero. Dependent …

Java CountDownLatch Read More »

Java Semaphore

Semaphore Introduction Semaphore is a synchronization primitive that can be used to ensure that only one thread can access a shared resource at any point of time. Semaphore guards critical sections of the code by providing the necessary signalling and prevents any race conditions. Semaphore controls access to shared resources by using counters. If the …

Java Semaphore Read More »

Java Callable Future Example

Java concurrent API support Callable and Future interfaces to implement threads that can return a value. One simple use case for a Callable object is to return status (Success/ Failure) of thread execution to the invoking object. More practical use cases include perform number crunching operations simultaneously wherein partial results could be return back to the …

Java Callable Future Example Read More »