问题:我想在spring boot项目中从webservice执行java jar文件。并希望监控它。
问题:我能够执行此流程,但问题是该流程未进一步处理。
我想知道为什么这个过程在等待以及为什么它没有被处理。我该如何监控其进展情况。
在以下条件下进行处理:
process.waitFor();
我尝试了来自this的解决方案,即从另一个线程执行该过程。
我的网络服务电话
@RequestMapping(value="/startAnalysis", method=RequestMethod.POST)
public String startAnalysis() {
List<String> cmd = new ArrayList<>();
cmd.add("java");
cmd.add("-jar");
cmd.add("test.jar");
try {
//Process p = Runtime.getRuntime().exec(cmd.toArray(new String[0]));
//ProcMon procMon = new ProcMon(cmd);
//Thread t = new Thread(procMon);
//t.setName("procMon");
//t.start();
ProcessBuilder processBuilder = new ProcessBuilder(cmd);
Process process = processBuilder.start();
process.waitFor();
} catch (Exception e) {
e.printStackTrace();
}
return "success";
}
先谢谢。
答案 0 :(得分:1)
通常,进程等待调用进程消耗它的输出。有时这只是意味着输出显示在终端上,但在这种情况下,您可能需要读取输入流直到它阻塞。如果您不知道该过程应该如何表现,您可能只想在单独的线程中读取process.getInputStream()。在某些状态下,您的进程也可能正在等待将某些内容写入process.getOutputStream()。
您需要检查jar的文档,或者直接从命令提示符/ shell执行它并尝试它的行为。然后,您可以更改应用程序以按预期的方式读取输出。
在许多应用中,输出最容易逐行读取:
final String EXPECTED_OUTPUT = "Hello World";
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String firstLine = reader.readLine();
if (!firstLine.equals(EXPECTED_OUTPUT)) {
// handle unexpected situation
}
// maybe handle some more output
// or send something to the process.getOutputStream() in response
// and finally wait for the application to exit when it should be done
process.waitFor();
答案 1 :(得分:0)
请详细说明在某些情况下process.waitFor()
对waitFor()
的调用根本不会返回的原因here。
或者,看看您是否可以使用我们提供timeOut值的2017-11-06 11:11:02,699 ERROR [Timer-Driven Process Thread-6]o.a.n.processors.hive.PutHiveStreaming PutHiveStreaming[id=819a7fe2-015f-1000-7097-cd3f8614c9c2] Error connecting to Hive endpoint: table oneviewtest3 at thrift://parent.rolta.com:9083
2017-11-06 11:11:02,699 ERROR [Timer-Driven Process Thread-6] o.a.n.processors.hive.PutHiveStreaming PutHiveStreaming[id=819a7fe2-015f-1000-7097-cd3f8614c9c2] Hive Streaming connect/write error, flow file will be penalized and routed to retry. org.apache.nifi.util.hive.HiveWriter$ConnectFailure: Failed connecting to EndPoint {metaStoreUri='thrift://parent.rolta.com:9083', database='default', table='oneviewtest3', partitionVals=[] }:
org.apache.nifi.processors.hive.PutHiveStreaming$ShouldRetryException: Hive Streaming connect/write error, flow file will be penalized and routed to retry. org.apache.nifi.util.hive.HiveWriter$ConnectFailure: Failed connecting to EndPoint {metaStoreUri='thrift://parent.rolta.com:9083', database='default', table='oneviewtest3', partitionVals=[] }
org.apache.nifi.processors.hive.PutHiveStreaming$ShouldRetryException: Hive Streaming connect/write error, flow file will be penalized and routed to retry. org.apache.nifi.util.hive.HiveWriter$ConnectFailure: Failed connecting to EndPoint {metaStoreUri='thrift://parent.rolta.com:9083', database='default', table='oneviewtest3', partitionVals=[] }
create table oneviewtest3 (TNT_KEY BIGINT, PLANT_KEY BIGINT, UNIT_KEY BIGINT, TAG_DATA_SRC STRING, TAG_DATA_RLVNC STRING, TAG_TYPE_ID STRING, DB_RQST_ID STRING, BATCH_KEY BIGINT, OPC_TAG_ID STRING, OPC_TAG_VAL_TS STRING, OPC_SRC_STM_CODE BIGINT, OPC_TAG_VAL STRING, OPC_QLTY_VAL BIGINT, REF_ID STRING, REF_TYPE STRING, ERROR_CODE STRING, OPC_TAG_VAL_AGG_TYPE STRING, OPC_TAG_RSMPL_INTRVL_VAL BIGINT, OPC_TAG_RSMPL_INTRVL_TYPE STRING, OPC_TAG_VAL_TS_PRC STRING, FLEX_FIELD1 STRING, FLEX_FIELD2 STRING, FLEX_FIELD3 STRING, FLEX_FIELD4 STRING, FLEX_FIELD5 STRING, ETL_BTCH_ID BIGINT) CLUSTERED BY (OPC_TAG_ID) into 4 buckets stored as orc tblproperties ("transactional"="true","orc.compress"="NONE");
方法。