Wednesday, April 24, 2019

Multithreading Interview Questions

 Multithreading interview questions in java.

Q- How many way to create thread in java ?
  • extends Thread Class
  • implements Runnable Interface
Q- What are the Thread States in multithreaded environment?
Thread Life Cycle in Java

  1.  New
  2.  Runnable
  3.  Running
  4.  Blocked/Waiting
  5.  Dead

Q- When to use Runnable and when to use Thread in Java?

Q-  Runnable interface Vs Callable interface in java ?

public interface Runnable {
 void run();
}

public interface Callable<V> {
 V call() throws Exception;
}
Q- What are the different methods in Thread Class ?

Q- What is the difference between wait() and sleep() ?

Q- How can two threads communicate to each other ?

Q- We can use wait() and notify() methods to communicate to each other. 

Q- What is the difference between start and run method in Thread ?

Q- Can we call start() methods more then one ?

Q- What happens if we call run() method instanceof start() method ? 

Q- What is the difference between execute vs submit java  ?

Q- What is the difference between Thread and Task ?

Task  : A task is something you want done.
A task is simply a set of instructions loaded into the memory.

Thread  : A thread is one of the many possible workers which performs that task.

Thread(s) are used to complete the operation by split the work into chunks and assigning to separate threads

Q- When to use Runnable and when to use Thread in Java?

Q- Why methods like wait(), notify() and notify all() are present in object class and not in Thread class?

Q- How to force start a thread in Java?
Answer:
In Java, multithreading one cannot force start a thread. Only thread scheduler can control threads and they are not exposed to any API for control.

Q- What is deadlock in java  ? 
Answer: 

Q- How to avoid deadlock in java ?
Answer:

Q- What is starvation problem in java ? How to avoid thread starvation in java ?
Answer:

Q- What is semaphore in java ?
Answer:

Q- What is the difference between semaphore and mutex?
Q- What is the difference between semaphore and binary semaphore?
Q- What are the significance of semaphores What are the different types of semaphores?
Q- What are the two types of semaphores?
Answer:
There are 3-types of semaphores.
  • Binary semaphore.
  • Counting semaphore.
  • Mutex semaphore.
Q- what is future interface in java ?
Answer:

Q- What is fairness policy in java multithreading  ?
Answer:- 

Q- What is Cyclicbarrier and CountDownLatch in java ?

Q- What is difference between Cyclicbarrier and CountDownLatch in java ?

No comments:

Post a Comment