File tree Expand file tree Collapse file tree
monitor/src/main/java/com/zfoo/monitor/util Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3434import java .util .ArrayList ;
3535import java .util .HashMap ;
3636import java .util .List ;
37- import java .util .Map ;
38- import java .util .concurrent .ConcurrentHashMap ;
39- import java .util .stream .Collectors ;
37+ import java .util .concurrent .TimeUnit ;
4038
4139/**
4240 * Oshi库封装的工具类,通过此工具类,可获取系统、硬件相关信息
@@ -281,24 +279,26 @@ public static String doExecCommand(String command, File wd) {
281279 .directory (wd )
282280 .start ();
283281
282+ var finished = process .waitFor (256 , TimeUnit .SECONDS );
283+ if (!finished ) {
284+ process .destroyForcibly ();
285+ throw new RunException ("doExecCommand timeout with process of command:[{}]" , command );
286+ }
287+
284288 //取得命令结果的输出流
285289 inputStream = process .getInputStream ();
286290 var bytes = IOUtils .toByteArray (inputStream );
287291 var result = StringUtils .bytesToString (bytes );
288292
289- // 其他线程都等待这个线程完成
290- process .waitFor ();
291- // 获取javac线程的退出值,0代表正常退出,非0代表异常中止
293+ // 获取线程的退出值,0代表正常退出,非0代表异常中止
292294 int exitValue = process .exitValue ();
293-
294- // 返回编译是否成功
295295 if (exitValue != 0 ) {
296- throw new RunException ("error executing command exitValue:[{}] result:[{}]" , exitValue , result );
296+ throw new RunException ("doExecCommand error executing command exitValue:[{}] result:[{}]" , exitValue , result );
297297 }
298298
299299 return result ;
300300 } catch (Exception e ) {
301- logger .error ("unknown exception in command execution" , e );
301+ logger .error ("doExecCommand unknown exception in command execution" , e );
302302 } finally {
303303 if (process != null ) {
304304 process .destroy ();
You can’t perform that action at this time.
0 commit comments