当前位置: 首页 > news >正文

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

  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();    }  }

http://www.lryc.cn/news/10159.html

相关文章:

  • RocketMQ 初步了解
  • Mac下PyCharm快捷键
  • 城市管网监测系统,保障城市血管生命线!
  • Web3中文|1月数据显示复苏迹象,涉及NFT、DeFi、Dapp、链游……
  • MySQL索引的介绍以及优缺点
  • Java_小项目书城
  • Unreal Engine08:Pawn的实现
  • 408强化(二)线性表纯享版
  • ubuntu下如何使用wireshark抓包,保姆级教程
  • 世界上最健康的程序员作息表!「值得一看」
  • Java中多继承的实现
  • 蓝桥杯 stm32 USART 串口发送数据
  • Spring之AOP底层源码解析
  • 人脸识别——景联文科技提供3D头模数据采集业务!
  • SpringBoot集成Flink-CDC 采集PostgreSQL变更数据发布到Kafka
  • 酷开系统壁纸模式,将氛围感死死拿捏!
  • 第0章 一些你可能正感到迷惑的问题
  • MYSQL实战
  • 少儿户外拓展北斗定位解决方案
  • 更换ssl证书
  • 线程池源码解析项目中如何配置线程池
  • Echarts 更改K线度颜色,解释K线图4个数字意义
  • JavaScript和Java两种方法实现百度地图和高德、腾讯地图的相互转换
  • Vue中常见的几种组件间通信方法
  • Outcome VS. Output:研发效能提升中,谁会更胜一筹?
  • ptp4l与phc2sys进行系统时钟同步
  • 使用注解JSON序列化
  • kubernetes教程 --Pod生命周期
  • 高校房产管理系统用到了哪些技术?
  • 【Python学习笔记】37.Python3 MySQL - mysql-connector 驱动(2)