线程没有被终止的异常的处理

  process = Runtime.getRuntime().exec(command);
            process.waitFor(); // 这个调用比较关键,就是等当前命令执行完成后再往下执行
            if (!file.exists()) {
                Ulog.error("html转pdf执行失败");
            } else {
                Ulog.info("html转pdf执行完成");
            }
        } catch (Exception e) {

InterruptedExceptions should never be ignored in the code, and simply logging the exception counts in this case as "ignoring". The throwing of the InterruptedException clears the interrupted state of the Thread, so if the exception is not handled properly the information that the thread was interrupted will be lost. Instead, InterruptedExceptions should either be rethrown - immediately or after cleaning up the method’s state - or the thread should be re-interrupted by calling Thread.interrupt() even if this is supposed to be a single-threaded application. Any other course of action risks delaying thread shutdown and loses the information that the thread was interrupted - probably without finishing its task.
Similarly, the ThreadDeath exception should also be propagated. According to its JavaDoc:
If ThreadDeath is caught by a method, it is important that it be rethrown so that the thread actually dies.

Compliant Solution
  public void run () {    try {      while (true) {        // do stuff      }    }catch (InterruptedException e) {      LOGGER.log(Level.WARN, "Interrupted!", e);      // Restore interrupted state...      Thread.currentThread().interrupt();    }  }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值