Archive for category concurrency


ArrayBlockingQueue implements BlockingQueue interface. ArrayBlockingQueue is a bounded blocking queue that stores it’s elements in an array internally. Queue orders elements in FIFO (first-in-first-out) order. The head of the array contains element that has been in the queue for the longest time and tail of the queue contains elements that have been in the queue […]

Leave a comment


A BlockingQueue is a concurrent data structure that extends Queue interface and supports additional operations with following characteristics: Wait for space to be available when an insert is attempted and queue is full Wait for element to be available when the queue is empty. Usage Scenario BlockingQueue is useful in producer-consumer type of scenarios. One […]

Leave a comment


Java concurrency API provides a synchronization utility java.util.concurrent.Exchanger that allows two threads to exchange data. Exchanger provides a common point where two threads arrive and exchange data between them such that data of first thread goes to the second thread and data of second thread goes to first. Exchanger basically creates a barrier at which […]

, , ,

Leave a comment

Using local thread variables

Shared data is one of the most critical aspect of concurrent programming. When you create an instance of a class that implements Runnable interface or extends Thread class and use same object to create multiple Threads then all the threads share same attributes. This means if you change any attribute in one thread, all threads […]

, , ,

Leave a comment

Difference between Wait and Sleep in Java

I am listing here differences between wait() and sleep() methods in java. Please feel free to suggest if you can think of anything apart from those listed below. Wait Sleep Wait method release the acquired monitor while the thread waits Sleep method holds the monitor while the thread goes to sleep Wait method should be […]

, ,

Leave a comment

Returning Data from Java Threads

There are a couple of ways in which threads can be created. i.e. Implementing Runnable Interface and extending Thread Class (Example here). Further we need to implement run method and do our processing inside the run method. This would look like below. One thing to note about above snippet is the return type of run() […]

, , , ,


Creating and Running thread in Java

Like any other Object in java, Threads are Objects. There are a couple of ways threads can be created in Java. Extending the Thread class and overriding it’s Run() method Building a class that implements Runnable Interface and implementing it’s run() method. Then create an Object of the Thread class and pass an instance of […]

, , ,

1 Comment