Write a java program to create multiple child threads and also ensures that main thread is last to stop

The Eduladder is a community of students, teachers, and programmers just interested to make you pass any exams. So we solve previous year question papers for you.
See Our team
Wondering how we keep quality?
Got unsolved questions?

Ask Questions
JAVA-AND-J2EE-06CS753--->View question


Write a java program to create multiple child threads and also ensures that main thread is last to stop ?

Write a note

By:scribed

Taged users:
|edu-Freak|sumesh|pallaviaithaln|scribed|arvindkhadri|arun|Anagha|manjarimattur|PerumalS|ram|asha|sangamithrapress

Likes:
Be first to like this question

Dislikes:
Be first to dislike this question

Talk about thisDelete|Like|Dislike|


Answers

An example program is as follows

// Controlling the main Thread. 
class CurrentThreadDemo { 
public static void main(String args[]) { 
Thread t = Thread.currentThread(); 
System.out.println("Current thread: " + t); 
// change the name of the thread 
t.setName("My Thread"); 
System.out.println("After name change: " + t); 
try { 
for(int n = 5; n > 0; n—) { 
System.out.println(n); 
Thread.sleep(1000); 

} catch (InterruptedException e) { 
System.out.println("Main thread interrupted"); 


}


metaphor

Likes:
Be first to like this answer

Dislikes:
Be first to dislike this answer
Talk about this|Once you have earned teacher badge you can edit this questionDelete|Like|Dislike|
------------------------------------

Can you help us to add better answer here? Please see this



Not the answer you're looking for? Browse other questions from this Question paper or ask your own question.

Join eduladder!