XXL-JOB使用命令行的方式启动python时,日志过多导致阻塞的解决方式
一、Runtime.getRuntime().exec()的阻塞问题 这个问题也不能算是XXL-JOB的问题,而是Java的Runtime.getRuntime().exec()造成的,BufferedReader的缓冲区大小有限,当不能及时从缓冲区中把输出取走,那么缓冲区满了之后就会导致程序阻塞; 1、如何解决 最简单的方式就是将正常输出和异常输出使用两个不同的线程进行操作 Process process = Runtime.getRuntime().exec(command); StreamOutter errorGobbler = new StreamOutter(process.getErrorStream(), "ERROR"); // any output? StreamOutter outputGobbler = new StreamOutter(process.getInputStream(), "OUTPUT"); // kick them off errorGobbler.start(); outputGobbler.start(); // command exit process.waitFor(); public class StreamOutter extends Thread { InputStream is; String type; public