pls explain this prog logic

Answer Posted / nachiyappan

class NewThread4 implements Runnable {

String name; // name of thread
Thread t;

NewThread4(String threadname) {
name = threadname;
t = new Thread(this, name);
System.out.println("New thread: " + t);
t.start(); // Start the thread
}
// This is the entry point for thread.
public void run() {
try {
for (int i = 5; i > 0; i--) {
System.out.println(name + ": " + i);
Thread.sleep(1000);
}
} catch (InterruptedException e) {
System.out.println(name + " interrupted.");
}
System.out.println(name + " exiting.");
}
}

class DemoJoin
{

public static void main(String args[])
{

NewThread4 ob1 = new NewThread4("One");
NewThread4 ob2 = new NewThread4("Two");
NewThread4 ob3 = new NewThread4("Three");
System.out.println("Thread One is alive: " +
ob1.t.isAlive());
System.out.println("Thread Two is alive: " +
ob2.t.isAlive());
System.out.println("Thread Three is alive: " +
ob3.t.isAlive());
// wait for threads to finish
try {
System.out.println("Waiting for threads to
finish.");
ob1.t.join();
ob2.t.join();
ob3.t.join();
} catch (InterruptedException e)
{
System.out.println("Main thread Interrupted");
}
System.out.println("Thread One is alive: " +
ob1.t.isAlive());
System.out.println("Thread Two is alive: " +
ob2.t.isAlive());
System.out.println("Thread Three is alive: " +
ob3.t.isAlive());
System.out.println("Main thread exiting.");
}
}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

what is elligibility criteria of hcl?

1844


Q1. A. Compare the advantages and disadvantages of a three- dimensional monitor using a varifocal mirror with a stereoscopic system. B. Write a routine to implement the polymarker function.

1791


i want to know ,If a five-digit number is input through the keyboard, write a program to calculate the sum of its digits.

1716


what is node class?

1743


Why does the 'divisibility by 3' rule work?

2629






What is the instruction to load the register B?

1840


discuss the conditional formatting and advanced filtering features in MS-Excel with suitable example

1360


What are the frequently asked technical engineer ques?

1404


what is the difference between composite key and primary key in sap abap

2118


am looking for ms,i got ielts score 5.5,and i dont have english score 60 in any any year.tell me can i get offer lettr from any university.is i am elegible..?

1737


What is The Need of Template?

1556


5. Tell me about a time you were able to successfully deal with another person even when that individual may not have personally liked you (or vice versa).

1568


tell me the e book for data structure (basic)

1618


hi... i just want to know that how could join the AAI with an B.E back ground??? please help me out.

1576


What is the pressure in co2 cartridge in a DCP 5 kg extinguisher.

2815