铁三角ck100停产:java编写一个用于继承Thread并创建两个线程,每个线程输出从1到5的数

来源:百度文库 编辑:高校问答 时间:2024/05/02 07:40:58

--------------------------napolun180410-----------------------------

public class MyThread extends Thread{
public void run(){
try{
for(int i=1;i<6;i++){
System.out.println(i);
sleep(2000);
}
}
catch(InterruptedException e){}
}
public static void main(String args[]){
System.out.println("当前的线程数:"+Thread.activeCount());
MyThread thread1=new MyThread();
thread1.start();
System.out.println("当前的线程数:"+Thread.activeCount());
MyThread thread2=new MyThread();
thread2.start();
System.out.println("当前的线程数:"+Thread.activeCount());
}
}

文件名 MyThread.java (注意大小写,别改文件名)

--------------------------有问题发消息我----------------------------