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
Hi i want some previous interview questions and answers for KVB Bank.
what is the concept of c++ class
i want a richdatatable to be displayed only when a list has some value in the bean, and a datatable with header only if the list is empty. And i want the datatable to be printed only when ajax button is clicked??
how to avoid a class from getting inherited but respective class should be able to instantiate ?
Tell me about a time when you had too many things to do and you were required to prioritize your tasks
What is Campus selection process of patni at Adcet,Ashta at 24th dec 2010.Also give apti syllabus.
sir ,,kindly provide me 10 year old solved question papers of gate ,i am from CS. branch...
is java supprot the complier time pollymorphism or run time pollymorphism ... why
Client server applications
What is the strongest naturally occurring material and how can it be cut?
What do you mean by client /server for a post scarcity world
My gre score is 283 and ielts is 5.5, will i get i20 for this score
WHAT IS DIFFERENT BETWEEN YOU AND OTHER APPLICANT TO GIVE YOU THE JOB
Why is it that a single, all – encompassing metric cannot be developed for programme complexity or programme quality?
Write a program to maintain a singly linked list having the following functions: a) Creation of the list b) Displaying the list. c) Swap all nodes at consecutive even odd positions. E.g.: The nodes at position 1 should be swapped with node 2, node 3 with node 4 and so on.