WEB开发网
开发学院WEB开发Jsp Java核心代码例程之:ThreadDemo.java 阅读

Java核心代码例程之:ThreadDemo.java

 2008-01-05 08:38:07 来源:WEB开发网   
核心提示:/** * Demo how threads in java work ***/public class ThreadDemo extends Thread{PRivate int startingNumber=0; public ThreadDemo(int startingNumber){this.starting

/**
 * Demo how threads in java work
 ***/
public class ThreadDemo
       extends Thread
{
  PRivate int startingNumber=0;
  
  public ThreadDemo(int startingNumber)
  {
    this.startingNumber=startingNumber;
  }
  
  
  // this method runs in a separate thread
  public void run()
  {
    //loop 10 times
    for (int i=startingNumber; i < (startingNumber+100); i++)
      System.out.println(i);
  }
  
  
  // test driver
  public static void main(String args[]) throws Exception
  {
    ThreadDemo t1=new ThreadDemo(100),
          t2=new ThreadDemo(200);
          
    t1.start();
    t2.start();
  }
}

Tags:Java 核心 代码

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接