/**
* <p>title: 创建多线程</p>
* <p>description: 使用构造器,创建多线程。</p>
* <p>copyright: copyright (c) 2003</p>
* <p>filename: multithread.java</p>
* @version 1.0
*/
public class multithread
{
/**
*<br>方法说明:主方法
*<br>输入参数:
*<br>返回类型:
*/
public static void main (string [] args){
new multithread();
}
/**
*<br>方法说明:构造器。构造多个线程,并启动它们。
*<br>输入参数:
*<br>返回类型:
*/
multithread(){
for (int i = 0; i < 5; i++){
system.out.println("creating thread "+i);
innthread mt = new innthread (i);
mt.start ();
}
}
/**
*<br>类说明:内部类通过继承thread实现线程
*<br>类描述:通过构造器参数,区别不同的线程
*/
class innthread extends thread
{
int count;
innthread(int i){
count=i;
}
/**
*<br>方法说明:内部类线程主体,继承thread必须实现的方法。
*<br>输入参数:
*<br>返回类型:
*/
public void run ()
{
system.out.println("now "+count+" thread is beginning..... ");
try{
sleep(10-count);
}catch(exception e){
system.out.println(e);
}
system.out.println(""+count+" thread is end!");
}
}
}
闽公网安备 35060202000074号