pls explain this prog logic



pls explain this prog logic..

Answer / 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

More Engineering AllOther Interview Questions

I have file with input as below : Name Value Rohan 12,13,14 Rohit 1,2,3 Output should be : Rohan 12 Rohan 13 Rohan 14 Here how will the normalize component work? Thanks

0 Answers   Cap Gemini,


Is printf(?%d?,p); valid?

0 Answers  


how u test the idoc in inbound and outbound?

0 Answers   HCL,


what should i say in the interview if interviewer asks me "why did you choose IT instead of your core group?"

0 Answers  


How to write test cases for Auditing in Health care Applications?

0 Answers  






What is the main difference between binary and counting semaphore?

0 Answers  


What are the file systems used in Linux?

0 Answers  


i mdoing btech and i have two choices either i choose software eng or do multimedia eng so which one has better scope

1 Answers  


what will happpen when "MY COMPUTER" IS PERMANENTLY REMOVED FROM MY COMPUTER?

2 Answers  


how can i write a program in c of SPARCE MATRIX(data structure)?

0 Answers  


What type of questions are asked in interview?

0 Answers  


What is the difference between a .PST file and a .OST file?

0 Answers   BMS,


Categories
  • Civil Engineering Interview Questions Civil Engineering (5085)
  • Mechanical Engineering Interview Questions Mechanical Engineering (4451)
  • Electrical Engineering Interview Questions Electrical Engineering (16632)
  • Electronics Communications Interview Questions Electronics Communications (3918)
  • Chemical Engineering Interview Questions Chemical Engineering (1095)
  • Aeronautical Engineering Interview Questions Aeronautical Engineering (239)
  • Bio Engineering Interview Questions Bio Engineering (96)
  • Metallurgy Interview Questions Metallurgy (361)
  • Industrial Engineering Interview Questions Industrial Engineering (259)
  • Instrumentation Interview Questions Instrumentation (3014)
  • Automobile Engineering Interview Questions Automobile Engineering (332)
  • Mechatronics Engineering Interview Questions Mechatronics Engineering (97)
  • Marine Engineering Interview Questions Marine Engineering (124)
  • Power Plant Engineering Interview Questions Power Plant Engineering (172)
  • Textile Engineering Interview Questions Textile Engineering (575)
  • Production Engineering Interview Questions Production Engineering (25)
  • Satellite Systems Engineering Interview Questions Satellite Systems Engineering (106)
  • Engineering AllOther Interview Questions Engineering AllOther (1379)