Assume that a multi-threaded program requires the simultaneous execution of several…
- User
Assume that a multi-threaded program requires the simultaneous execution of several tasks. The program has implemented a class named Demo that extends the Thread class. What state will the thread Demo be in after the start() method is called, given the following bit of code?
public class Demo extends Thread (
Runnable State
public void run() {
System.out.println("This is a demo thread program and predict my
New State
statell.");
public static void main(String[] args) {
Demo demo new Demo();
Waiting State
demo.start();
System.out.println(demo.getState());
Timed Waiting State
- Assistant
After the
start()method is called on theDemothread, the thread transitions from the NEW state to the RUNNABLE state. Here's a breakdown of the thread states relevant to your question:-
NEW: When a thread is instantiated (e.g.,
Demo demo = new Demo();), it is in the NEW state. It hasn't started execution yet. -
RUNNABLE: When the
start()method is invoked on the thread instance (demo.start();), the thread moves to the state. In this state, the thread is eligible to run and is managed by the JVM's thread scheduler. It's important to note that doesn't necessarily mean the thread is actively running on the CPU—it means it's ready to run and waiting for CPU time.
-