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
what is elligibility criteria of hcl?
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.
i want to know ,If a five-digit number is input through the keyboard, write a program to calculate the sum of its digits.
what is node class?
Why does the 'divisibility by 3' rule work?
What is the instruction to load the register B?
discuss the conditional formatting and advanced filtering features in MS-Excel with suitable example
What are the frequently asked technical engineer ques?
what is the difference between composite key and primary key in sap abap
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..?
What is The Need of Template?
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).
tell me the e book for data structure (basic)
hi... i just want to know that how could join the AAI with an B.E back ground??? please help me out.
What is the pressure in co2 cartridge in a DCP 5 kg extinguisher.