这个问题也不能算是XXL-JOB的问题,而是Java的Runtime.getRuntime().exec()形成的,BufferedReader的缓冲区大小有限,当不能及时从缓冲区中把输出取走,那么缓冲区满了以后就会致使程序阻塞;java
最简单的方式就是将正常输出和异常输出使用两个不一样的线程进行操做spring
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 StreamOutter(InputStream is, String type) { this.is = is; this.type = type; } public void run() { System.out.println("进入" + type + "处理线程"); BufferedReader br = null; try { InputStreamReader isr = new InputStreamReader(is); br = new BufferedReader(isr); String line; System.out.println("开始处理" + type + "线程数据"); while ((line = br.readLine()) != null) { XxlJobLogger.log(line); } } catch (IOException ioe) { ioe.printStackTrace(); } finally { if (br != null) { try { br.close(); } catch (IOException e) { e.printStackTrace(); } } } } }
br = new BufferedReader(isr); int one = null; if((one=br.read()) != -1){ System.out.println((char) one); }
br.read()是挨个取出全部字符,因此须要进行对one进行拼接后在使用\n进行拆分,有点相似于,一次性读出文件的全部内容的方式,须要本身进行处理后获得行数据springboot
我这里使用第一种方式已经没有问题了,至于第二种方式则须要自行探索了,若是有使用第二中方式解决的同窗,能够指点一二;dom
java -jar xxx.jar aaa bbb ccccthis
传了3个参数,分别是aaa,bbb,ccc命令行
经过main方法的参数获取线程
java -jar xxx.jar --test.test=aaa --domain=bbbcode
是springboot的写法,能够经过@Value("${test.test}")@Value("${domain}") 获取get
我的博客 蜗牛博客