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
why IT?
2. A product selected for testing is equally likely to have been produced by one the 6 machines/processes. (i) Determine sample space āSā (ii) What is the probability that the product is from machine 1? (iii) What is the probability that the product is from machine 2 or machine 4? (iv) What is the probability that the product is from both machine 5 and machine 3? (v) What is the probability that the product is not from machine 6? (vi) What is the probability that the product is not from either machine 6 or machine 1?
defference between menu and context menu in vb.net?
What is the significance of superconductors?
WAP in Java to print the format AMIT M I T
What is the difference between command line argument and input taking from the user?
hi my name is ashok i have 55 per and 2 backlogs and one year left may i get above 60 pr
Briefly describe an experience of yours that illustrates your ability to clearly articulate and explain technical issues in a nontechnical manner
Hello, I need to compare, using a cobol program, two cobol skeletons. I don't know if it is easy to do this or it will be so complicated. I wanna have your opinions. Thanks a lot
what does complexity means in an algorithim?? how it is calcutaed?
how to generate linked implementation of sparse matrix?
What is the allowable load carrying capacity of a circular column section of 400 mm diameter reinforced with 6x25 mm diameter bars adequately tied with spirals? Consider concrete of grade M25 and steel of grade Fe 415.
how will u send the idoc
What is the use of generics? when was it added to jdk?
one fuse has following data 80A 415V -6.9W HN SIZE 00 100 KA gG Please tell me about what is the mean of 100kA gG