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();
}
}
赞助商链接