Author: Rakesh Singh

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 – time-sliced On Solaries – pre-emptive On Windows- pre-emptive before JDK-1.0.2, after…

Read the full article

In a Producer & Consumer thread problem, producer thread has acquired the lock and multiple consumer threads are in wait pool, which consumer thread gets notified first, once producer thread calls notify?

Answer: The thread that it notifies depends on JVM implementation. We can’t really say which thread actually gets notified. It could be the first thread, it could be the last thread which went into the wait pool or it could be the highest priority thread. Most often the JVM implementation is as first thread goes…

Read the full article

What is difference between BLOCKED and WAITING state in java multithreading?

Answer: Difference between blocked and waiting state of Java thread. BLOCKED state: If a thread is waiting for a lock to enter a synchronized block/method is called blocked. Note – Also, when a thread wants to re-enter a synchronized block/method after calling wait () method is also called blocked. WAITING state: a thread, that is…

Read the full article

We have 50 classes and out of these we want to make 10 classes noncopyable, means, we cannot copy or assign objects of same class type. How would you achieve this? Note that we cannot change the body of classes.

Answer: One of the solutions is, create a separate base class, say “NonCopyable” and make copy constructor and assignment operator declaration private leaving constructor and destructor public or having default constructor. When we create object of existing class it will first call the constructor of base(NonCopyalbe) class then existing class. Same will happen for copy…

Read the full article