Top 100+ Java Multithreading Interview Questions and Answers - 1

Question: 1

What are concurrent collection classes?

Java Collection Classes are fail fast which means that if the Collection will be changed while some thread is traversing over it using iterator, the iterator.next() will throw ConcurrentModificationException.

Concurrent collection classes supports full concurrency of retrievals and adjustable expected concurrency for updates.

Question: 2

What are the states associated in the thread?

Thread contains ready, running, waiting and dead states.

Question: 3

What are different ways in which a thread can enter the waiting state?

A thread can enter the waiting state by the following ways

Invoking its sleep() method,

By blocking on I/O

By unsuccessfully attempting to acquire an object’s lock

By invoking an object’s wait() method

It can also enter the waiting state by invoking its (deprecated) suspend() method.

Question: 4

What are the benefits of multi threaded programming?

In Multi Threaded programming, multiple threads are executing concurrently that improves the performance because CPU is not idle incase some thread is waiting to get some resources.

Multiple threads share the heap memory, so it’s good to create multiple threads to execute some task rather than creating multiple processes.

Question: 5

Explain Java Thread Life Cycle?

The life cycle of threads in Java is very similar to the life cycle of processes running in an operating system.

During its life cycle the thread moves from one state to another depending on the operation performed by it or performed on it.

A Java thread can be in one of the following states.

New: A thread that is just instantiated is in the new state. When a start() method is invoked, the thread moves to the ready state from which it is automatically moved to runnable state by the thread scheduler.

Runnable: A thread executing in the JVM is in running state.

Blocked: A thread that is blocked waiting for a monitor lock is in this state. This can also occur when a thread performs an I/O operation and moves to next (runnable) state.

Waiting: A thread that is waiting indefinitely for another thread to perform a particular action is in this state.

Timed_waiting: A thread that is waiting for another thread to perform an action up to a specified waiting time in this state.

Terminated: A thread that has exited is in this state.

Related Questions