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

why IT?

1481


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?

1524


defference between menu and context menu in vb.net?

2381


What is the significance of superconductors?

599


WAP in Java to print the format AMIT M I T

1608






What is the difference between command line argument and input taking from the user?

1397


hi my name is ashok i have 55 per and 2 backlogs and one year left may i get above 60 pr

1355


Briefly describe an experience of yours that illustrates your ability to clearly articulate and explain technical issues in a nontechnical manner

1781


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

1477


what does complexity means in an algorithim?? how it is calcutaed?

1964


how to generate linked implementation of sparse matrix?

1495


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.

1624


how will u send the idoc

2127


What is the use of generics? when was it added to jdk?

1670


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

1866