Category: Threads

Examples on Threads, Concurrencies

BlockingQueue

BlockingQueue is a thread-safe queue where we can enqueue on one end of queue, and dequeue on another end of queue., All BlockingQueue implementions on array or linked queues are thread-safe implementations....

BlockingDeque

BlockingDeque is an extended implementation of queue where we can enqueue or dequeue on both ends of the queue. All BlockingDeque implementions on array or linked queues are thread-safe implementations. Below is...

Threads (Runnable vs Thread)

1.What is Thread? A thread in Java is nothing but an instance of class which is running independently to complete its job.Thread is created in Java with the help of java.lang.Thread class,...

CountdownLatch

CountDownLatch is another concurrency class, in which makes one thread wait for other until it reaches the threshold limit mentioned.Reach for the threshold limit, is counted by calling countdown() method present in...

ForkJoinPool

ForkJoinPool is the core of the concurrency frameworks which follows divide and conquer approach in completing the tasks. Fork – Recursively break the single task into multiple smaller tasks till the threshold....

Reentrant Lock

The ReentrantLock class is an implementation of Lock Interface, which will lock() the execution block for the thread which calls it.Until the locked thread calls the lock.unlock() method, the code block in...

Cyclic Barrier

Assume a the conference call will be opened when 4 users join., Assume until all the users join, that conference call wont be opened even when the less than 4 users join....

Executor & Executor Service

Executor and ExecutorService are the utility classes present starting from JDK 1.5 for executing a java process/block parallely in a controlled manner. Executor – Executor is used for creates a thread pool to for...

Semaphore

A semaphore maintains a fixed number of threads in executions if exceeds lock can be acquired for that semaphore thread. Below method will get the lock of semaphore within semaphore.availablePermits()

If there...