To make a thread execute, you call its start() method. : Thread Starting « Thread « SCJP

Home
SCJP
1.Java Source And Data Type
2.Operators
3.Modifiers
4.Type Casting
5.Statements
6.Object Oriented
7.Thread
8.Utility Classes
9.File
SCJP » Thread » Thread Starting 
7.2.1.To make a thread execute, you call its start() method.
public class MainClass{
    public static void main(String[] argv){
    new MyThread().start();
    }
    }
    
 class MyThread extends Thread {
   public void run() {
     for (int i = 1; i <= 10; i++) {
      System.out.println("Counting: " + i);
     }
   }
 }
Counting: 1
Counting: 2
Counting: 3
Counting: 4
Counting: 5
Counting: 6
Counting: 7
Counting: 8
Counting: 9
Counting: 10



You do not call the run method directly; instead, call the start method and the Thread will execute run.

A thread is done being a thread when its target run() method completes. 

Once a thread has been started, it can never be started again. 

The order in which runnable threads are chosen to run is not guaranteed.
7.2.Thread Starting
7.2.1.To make a thread execute, you call its start() method.
7.2.2.To start a thread: construct an instance of MyThread and then invoke its start() method
7.2.3.Starting a Thread
7.2.4.Instantiates a thread and gives it a name, and then the name is printed out from the run() method
7.2.5.Starting and Running Multiple Threads
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.