java.lang.IllegalThreadStateException

java.lang.IllegalThreadStateException

继承

java.lang.Thread类

对象重复调用start方法的话,会出现java.lang.IllegalThreadStateException异常。
public class ThreadTest extends Thread{  
    private String name;  
    public ThreadTest(String name) {  
       this.name=name;  
    }  
    public void run() {  
        for (int i = 0; i < 5; i++) {  
            System.out.println(name + "运行  :  " + i);  
            try {  
                sleep((int) Math.random() * 10);  
            } catch (InterruptedException e) {  
                e.printStackTrace();  
            }  
        }  
         
    }  
    
    public static void main(String[] args) {  
    	ThreadTest mTh1=new ThreadTest("A");     	
        ThreadTest mTh3=mTh1;  
        mTh1.start(); 
        mTh3.start();  
    }  
}  


你可能感兴趣的:(java)