Explain Java BlockingQueue with Producer-Consumer thread example

Java BlockingQueue interface is used to implement producer consumer design pattern. This design pattern comes to solve common problem, in which producer and consumer threads use the same queue to pass over the information. In the Blocking Queue, producer will put elements and wait Read more →

How many ways we can create a thread in Java? Explain with pseudo code.

There are two ways we can create a thread in multithreading in java programs that is by extending thread class and implementing Runnable interface. Here are simple steps to create threads in java for both ways i.e. by extending Thread class and Runnbale Interface. Read more →

Callable Vs Runnable interface in Java multithreading?

Callable Vs Runnable interface in Java Multithreading. A Callable can return a result but a Runnable interface cannot. A Callable can throw checked exception but a Runnable cannot. Callable provides call() method to implement and Runnable interface provides run() method to implement in java. Read more →

What is difference between pre-emptive scheduling and non-pre-emptive scheduling?

Answer: Pre-emptive scheduling: In this scheduling the highest priority thread runs when it has a chance to do so. This means that an executing lower-priority thread must yield the CPU to a thread with a higher priority that is ready to run. Non-pre-emptive Scheduling: Read more →

What thread-scheduling algorithm is used in Java?

Answer: There are two algorithms, used for Java thread scheduling. Time sliced based scheduling algorithm, also known as Round-Robine algorithm. Pre-emptive scheduling.   Read difference between preemptive and non preemptive scheduling   Java uses different scheduling algorithm on different platforms e.g. On Mac – Read more →