Java run async processes

前端 未结 3 835
野趣味
野趣味 2020-12-19 05:10

I am trying to run an async process and I do not want the program to wait until the end of these processes executions. I found this question how to run shell script asynchro

3条回答
  •  误落风尘
    2020-12-19 05:59

               Thread commandLineThread = new Thread(() -> {
                try {
                    BufferedReader br=new BufferedReader(
                            new InputStreamReader(
                                    process.getInputStream()));
                    String line;
    
                    while((line=br.readLine())!=null){
                        System.out.println(line);
                    }
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
            });
            commandLineThread.setDaemon(true);
            commandLineThread.start();
    

提交回复
热议问题