Java programming language provides the Concurrency API which provides a high-level threading facility that is easier to use compared to the low-level threading facility using Thread and Runnable. Though most of the java concurrency interview questions are related to low-level threading, you will also find questions related to the Java concurrency API.
Java concurrency API and its application is an advanced Java topic. Your knowledge and proper responses to Java concurrency interview questions will provide you a definite edge over other candidates..
Below Java concurrency interview questions, answers, tips and samples will get you grounded on the fundamentals; helps you to memorize some important methods, and review the basic operations that you will frequently perform using Java collections API.
Important keywords are provided at the end of the questions. Review them, make them a part of your Java concurrency vocabulary, and talk about them confidently during your interview process.
Java Concurrency framework contains classes in the java.util.concurrent package that provide a high-level abstraction for creating and executing multi-threaded programs, instead of low-level multithreading via explicit thread creation and execution.
The key classes provided in the Java Concurrency framework are Executor, ExecutorSevice, Callable, and Future.
Executor is a class provided in the Java Concurrency Framework that is used to submit a task for execution without controlling how or when the task is executed. Executor decouples the task that needs to be executed from the creation and starting of threads.
ExecutorService which extends from Executor, adds additional functionality to an Executor. ExecutorService has the ability to execute Callables and return Futures.
Executors is a class provided in the Java concurrency framework that provides factory methods to get different kinds of executors.
There are four kinds of Executors.
1. Cached Thread Pool Executors – A cached thread pool executor will create new threads when they are needed and will reuse existing threads in the pool that are free. Threads that are not used for 1 min are removed from the pool.
*** See complete answer in the Java Interview Guide
Callable is a functional interface similar to Runnable but return a value. Callable are submitted to ...
*** See complete answer in the Java Interview Guide
Parallel Fork-Join framework is used for highly parallelizable tasks. Parallel Fork-Join framework increases ...
*** See complete answer in the Java Interview Guide
A parallel fork-join task represents the problem to solve. When executed by a fork-join pool ...
*** See complete answer in the Java Interview Guide
RecursiveTask’s compute() method returns a value, whereas RecursiveAction’s compute() method returns void...
*** See complete answer in the Java Interview Guide
Atomic variables are thread-safe variable classes provided in Java Concurrency framework in the java.util.concurrent.atomic package. Atomic variables can be used for ...
*** See complete answer in the Java Interview Guide
Scheduled executors enables tasks to be executed after a delay or at regular intervals...
*** See complete answer in the Java Interview Guide
Concurrent collections are collection classes provided in the Java concurrency framework that are thread-safe, and in addition are ...
*** See complete answer in the Java Interview Guide
Copy-on-write collections are thread-safe and lock-safe collections provided in the Java concurrency framework. These collections are implemented ...
*** See complete answer in the Java Interview Guide