Category: 05. Java Concurrency
-
ConcurrentNavigableMap Interface
A java.util.concurrent.ConcurrentNavigableMap interface is a subinterface of ConcurrentMap interface, and supports NavigableMap operations, and recursively so for its navigable sub-maps, and approximate matches. ConcurrentMap Methods Sr.No. Method & Description 1 NavigableSet<K> descendingKeySet()Returns a reverse order NavigableSet view of the keys contained in this map. 2 ConcurrentNavigableMap<K,V> descendingMap()Returns a reverse order view of the mappings contained…
-
ConcurrentMap Interface
A java.util.concurrent.ConcurrentMap interface is a subinterface of Map interface, supports atomic operations on underlying map variable. It have get and set methods that work like reads and writes on volatile variables. That is, a set has a happens-before relationship with any subsequent get on the same variable. This interface ensures thread safety and atomicity guarantees.…
-
BlockingQueue Interface
A java.util.concurrent.BlockingQueue interface is a subinterface of Queue interface, and additionally supports operations such as waiting for the queue to become non-empty before retrieving an element, and wait for space to become available in the queue before storing an element. BlockingQueue Methods Sr.No. Method & Description 1 boolean add(E e)Inserts the specified element into this…
-
Fork-Join framework
The fork-join framework allows to break a certain task on several workers and then wait for the result to combine them. It leverages multi-processor machine’s capacity to great extent. Following are the core concepts and objects used in fork-join framework. Fork Fork is a process in which a task splits itself into smaller and independent…
-
Futures and Callables
java.util.concurrent.Callable object can return the computed result done by a thread in contrast to runnable interface which can only run the thread. The Callable object returns Future object which provides methods to monitor the progress of a task being executed by a thread. Future object can be used to check the status of a Callable…
-
ScheduledThreadPoolExecutor Class
java.util.concurrent.ScheduledThreadPoolExecutor is a subclass of ThreadPoolExecutor and can additionally schedule commands to run after a given delay, or to execute periodically. ScheduledThreadPoolExecutor Methods Sr.No. Method & Description 1 protected <V> RunnableScheduledFuture<V> decorateTask(Callable<V> callable, RunnableScheduledFuture<V> task)Modifies or replaces the task used to execute a callable. 2 protected <V> RunnableScheduledFuture<V> decorateTask(Runnable runnable, RunnableScheduledFuture<V> task)Modifies or replaces the…
-
ThreadPoolExecutor Class
java.util.concurrent.ThreadPoolExecutor is an ExecutorService to execute each submitted task using one of possibly several pooled threads, normally configured using Executors factory methods. It also provides various utility methods to check current threads statistics and control them. ThreadPoolExecutor Methods Sr.No. Method & Description 1 protected void afterExecute(Runnable r, Throwable t)Method invoked upon completion of execution of…
-
newSingleThreadExecutor Method
A single thread pool can be obtainted by calling the static newSingleThreadExecutor() method of Executors class. Syntax Where newSingleThreadExecutor method creates an executor that executes a single task at a time. Example The following TestThread program shows usage of newSingleThreadExecutor method in thread based environment. This will produce the following result. Learn Java in-depth with real-world projects…
-
newScheduledThreadPool Method
A scheduled thread pool can be obtainted by calling the static newScheduledThreadPool() method of Executors class. Syntax Example The following TestThread program shows usage of newScheduledThreadPool method in thread based environment. This will produce the following result. Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.…
-
newCachedThreadPool Method
A cached thread pool can be obtainted by calling the static newCachedThreadPool() method of Executors class. Syntax where Example The following TestThread program shows usage of newCachedThreadPool method in thread based environment. This will produce the following result. Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your…