Runtime.getRuntime().exec()进程阻塞问题
来源:互联网 发布:金税盘开票软件最新版 编辑:程序博客网 时间:2024/04/30 02:07
今天在用Runtime.getRuntime().exec()时代码走了一个或者两个小时后就会自动阻塞,网上找到了原因,是因为没有对Process的输出信息及时清理导致进程阻塞,服务失效。于是,在Runtime.getRuntime().exec()之后,p.waitFor()之前加入如下线程代码:
String cmds_ = "/usr/bin/pdf2htmlEX --no-drm 1 --split-pages 1 "+ "--embed-css 0 --embed-javascript 0 --embed-image 0 --embed-font 0 --css-filename html.css "+ "--fit-width 700 --bg-format jpg --auto-hint 1 --svg-node-count-limit 1 --auto-hint 1 "+ "--embed-external-font 0 --dest-dir " + htmlPath + " --page-filename "+ path[path.length - 1].replace(".pdf", "") + "-%d.page " + pdfPath;String[] cmds = { "/bin/sh", "-c", cmds_ };Process pro = Runtime.getRuntime().exec(cmds);StreamGobbler errorGobbler = new StreamGobbler(pro.getErrorStream(), "Error");StreamGobbler outputGobbler = new StreamGobbler(pro.getInputStream(), "Output");errorGobbler.start();outputGobbler.start();pro.waitFor();
StreamGobbler类:<pre name="code" class="java">public class StreamGobbler extends Thread { InputStream is; String type; public StreamGobbler(InputStream is, String type) { this.is = is; this.type = type; } public void run() { try { InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); String line = null; while ((line = br.readLine()) != null) { if (type.equals("Error")) { System.out.println("Error :" + line); } else { System.out.println("Debug:" + line); } } } catch (IOException ioe) { ioe.printStackTrace(); } } }
0 0
- Runtime.getRuntime().exec()进程阻塞问题
- Runtime.getRuntime().exec()进程阻塞问题
- Runtime.getRuntime().exec(command)的阻塞问题
- Runtime.getRuntime().exec() 输出流阻塞问题
- Runtime.getRuntime().exec问题
- java调用命令行Runtime.getRuntime().exec()阻塞问题
- Runtime.getRuntime().exec执行阻塞问题解决
- Runtime.getRuntime().exec()执行阻塞问题解决
- Runtime.getRuntime().exec执行阻塞问题解决 .
- java调用命令行Runtime.getRuntime().exec()函数碰到的阻塞问题
- Runtime.getRuntime().exec() 输出流阻塞的解决方法
- Runtime.getRuntime().exec();里面产生停滞(阻塞,blocking)
- Runtime.getRuntime().exec()执行一连串命令阻塞解决
- Runtime.getRuntime().exec()出现阻塞,导致后续程序无法运行!
- Runtime.getRuntime().exec() 输出流阻塞的解决方法
- Runtime.getRuntime(). exec( )
- java Runtime.getRuntime().exec
- Runtime.getRuntime().exec
- 数组中未出现的最小正整数
- MATLAB中cell函数
- STC单片机使用RS485下载程序方法
- android存储方式之文件存储
- 面试编程加数据库
- Runtime.getRuntime().exec()进程阻塞问题
- Android button按键点击无反应
- github-july-最长回文子串
- Web Service 的工作原理
- android学习笔记(19)数据库sqlite进阶
- NMCUSTOMDRAW
- Linux下配置用msmtp和mutt发邮件
- 【Splay】 HDU 1890 Robotic Sort 翻转
- HDU1053 - Entropy (哈夫曼树)