zoukankan      html  css  js  c++  java
  • java多线程(2)连续重启一个线程报错

    package com.javaconcurrencyprogramming.chapter1;

    import java.util.concurrent.TimeUnit;

    /**
    * @description: 一个线程不能重复启动
    * @author:
    * @create:
    **/

    public class RestartThreadError {

    public static void main(String[] args) {

    Thread thread = new Thread(){

    public void run(){
    try {
    TimeUnit.SECONDS.sleep(10);

    }catch (InterruptedException e){
    e.printStackTrace();
    }
    }
    };

    thread.start();//启动线程

    thread.start();//重启线程报IllegalThreadStateException异常
    }


    }



    //重新激活一个线程报IllegalThreadStateException

    package com.javaconcurrencyprogramming.chapter1;

    import java.util.concurrent.TimeUnit;

    /**
    * @description: 一个线程不能重复启动
    * @author:
    * @create:
    **/

    public class RestartThreadError {

    public static void main(String[] args) throws InterruptedException {

    Thread thread = new Thread(){

    public void run(){
    try {
    TimeUnit.SECONDS.sleep(1);

    }catch (InterruptedException e){
    e.printStackTrace();
    }
    }
    };

    thread.start();

    TimeUnit.SECONDS.sleep(4);

    thread.start();//重启线程报IllegalThreadStateException异常
    }


    }
  • 相关阅读:
    bzoj 1232 [Usaco2008Nov]安慰奶牛cheer
    bzoj 1237 [SCOI2008]配对 贪心+dp
    缺8数
    缺8数
    Binary GCD algorithm
    Binary GCD algorithm
    HDU1576 A/B (解法二)【试探法】
    HDU1576 A/B (解法二)【试探法】
    I00002 打印九九乘法表
    I00002 打印九九乘法表
  • 原文地址:https://www.cnblogs.com/herosoft/p/10737026.html
Copyright © 2011-2022 走看看