Can we override start method of thread class in java?

Answer: Yes, we can override start() method of thread in Java, the same way we override any other methods. for example, In below, custom thread class MyThread, both start() method and run() method have been overridden. When we create an object of custom thread and call start() method, run() will be automatically called. You may…

Read the full article

what is minimum thread priority in java thread programming?

The minimum thread priority in java is 1 and maximum or highest thread priority is 10. We will see a program example to set and get thread priority. Default priority of thread in java is = 5. Minimum thread Priority = 1 Maximum thread Priority = 10 We can set priority of a thread within…

Read the full article

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: This scheduling is based on the order of the threads waiting…

Read the full article

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

Does each thread have its own copy of JVM instance?

Answer: No, by definitions threads in a Java application share the same memory space, therefore, they are executing within the same JVM. This way you can easily share objects across multiple threads, perform synchronization and such, all that is happening within the JVM. One way to see it is that processes have their own memory…

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

What is daemon thread? When would you use daemon thread?

Answer: A daemon thread in Java is a thread that runs in the background within same process. Daemon threads are like Service providers for other threads running in the same process. Daemon threads are used for background support task like handling request or events etc. and are only needed while normal threads are running. Daemon…

Read the full article

Which method is used to create a daemon thread?

Answer: setDaemon(boolean value) – Set it to “true” to make thread as a daemon thread. Notes: It is mandatory to call this method before thread start() method. All threads created by a programmers are user threads/normal threads unless you marked it as a daemon thread using the method setDaemon(boolean value). Example:  

Can we overload destructor of a class in C++?

Answer: No, destructor of a class in C++ cannot be overloaded. Only one empty destructor per class should be there. It must have a void parameter list. Destructor in C++ neither takes any parameters nor does it return anything. So, multiple destructor with different signatures are not possible in a class. Hence, overloading is also…

Read the full article