int execVal = process.waitFor();
에서 무한 대기하는 현상
Back : Spring Framework
Front : RestAPI를 수신하는 SPA 방식
Computer : Window
WAS : Jetty
bReader = new BufferedReader(new java.io.InputStreamReader(process.getInputStream(), "utf-8"));
int exitVal = process.waitFor(); // 프로세스가 종료될 때까지 대기
while ((line = bReader.readLine()) != null) {
log.info(line);
}
process.waitFor()에서 정지한다는 것은 프로세스가 정상적으로 실행이 되지 않았거나, 의도치 않을 때 먼저 종료된 경우 일 것으로 특정할 수 있다.
BufferedReader가 프로세스가 종료되어 출력 스트림을 읽지 못하면 교착상태에 빠질 수 있습니다.
만약 프로세스의 종료까지 대기하는 process.waitFor()의 위치를 스트림 이후로 옮긴다면 Log를 받을 수 있지 않을까 싶어 아래와 같이 코드를 수정했습니다.
bReader = new BufferedReader(new java.io.InputStreamReader(process.getInputStream(), "utf-8"));
while ((line = bReader.readLine()) != null) {
log.info(line);
}
int exitVal = process.waitFor(); // 프로세스가 종료될 때까지 대기
process.getErrorStream().close();
process.getInputStream().close();
process.getOutputStream().close();
https://stackoverflow.com/questions/5483830/process-waitfor-never-returns