-2
我是Core Java的初学者,现在我正在学习多线程。我有一个与此相关的代码一个疑问:多线程中的非法状态异常
import java.io.*;
public class MyThread extends Thread
{
public void run()
{
for(int i=0;i<10;i++)
{
try
{
Thread.sleep(500);
}
catch(InterruptedException e)
{
System.out.println(e);
}
System.out.println(i);
}
}
public static void main(String args[])
{
MyThread mt=new MyThread();
MyThread mt1=new MyThread();
mt.start();
mt.start();
}
}
上面的代码编译,但我得到了在运行时的非法状态异常。这是什么原因?