线程对象不能多次调用start函数开辟线程

来源:互联网 发布:小意思托福 mac 编辑:程序博客网 时间:2024/05/23 14:28
同一个线程对象是不能多次调用start函数开辟线程
(例)以下代码的12行会报错,虽然12行代码执行时第一次开辟线程运行的run函数已经结束
代码:
1)  public class MyThread extends Thread {
2)     @Override
3)     public void run() {
4)        for (int i = 0; i < 3; i++) {
5)           System.out.println(i);
6)        }
7)     }
8)     public static void main(String[] args) throws Exception {
9)        Thread thread = new MyThread();
10)       thread.start();
11)       Thread.sleep(5000);
12)       thread.start();
13)    }

14) }

出处:http://blog.csdn.net/wangguangrong/article/details/8262092

0 0