Multithreading in Java
page 2 of 5
by Debjani Mallick
Feedback
Average Rating: 
Views (Total / Last 10 Days): 24270/ 28

Main Thread

It is the entry point from where the execution begins. Every Java program contains at least one thread which is called the main thread. It is the entry point from where the execution begins and from the main thread, we can start other threads. By default there is a main thread existing in every Java program.

Listing 1

class threadDemo
{
  public static void main(String a[])
  {
    Thread t = Thread.currentThread();
    System.out.println("Current Thread: " + t);
    t.setName("Demo");
    System.out.println("After changing the name, the thread is " + t);
    for (int i = 5; i > 0; i--)
    {
      System.out.println("Current Thread: " + i);
      t.sleep(1000);
    }
  }
}

While doing a multithreading program, the main thread should terminate only after all the other threads get terminated.


View Entire Article

User Comments

Title: good   
Name: sathyaraj
Date: 2008-07-01 4:52:18 AM
Comment:
we learn more about multithreading .............
Title: Thread program not working   
Name: Thread program not working
Date: 2008-04-30 6:25:37 AM
Comment:
Listing 1
Thread program not working
Title: Very Nice   
Name: Ajit
Date: 2007-08-20 3:20:09 AM
Comment:
Keep Up
Title: Nice   
Name: Jonas
Date: 2007-08-15 10:48:08 AM
Comment:
Its a good piece of writing
Title: Good   
Name: Rocky
Date: 2007-08-14 10:37:54 PM
Comment:
Keep up the good work

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-26 12:55:23 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search