提交 1ad9a146 编写于 作者: J jialinsun

fix cat-agent bug of runing process open too many files

上级 55d17ce8
package com.dianping.cat.agent.monitor;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.List;
......@@ -12,26 +11,34 @@ public class CommandUtils {
public List<String> runShell(String cmd) throws Exception {
List<String> result = new LinkedList<String>();
BufferedReader reader = null;
InputStreamReader sReader = null;
BufferedReader bReader = null;
Process process = null;
try {
Process process = Runtime.getRuntime().exec(new String[] { "/bin/sh", "-c", cmd });
reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
process = Runtime.getRuntime().exec(new String[] { "/bin/sh", "-c", cmd });
sReader = new InputStreamReader(process.getInputStream());
bReader = new BufferedReader(sReader);
String line = null;
while ((line = reader.readLine()) != null && StringUtils.isNotEmpty(line)) {
while ((line = bReader.readLine()) != null && StringUtils.isNotEmpty(line)) {
result.add(line);
}
} catch (Exception e) {
throw new Exception(e);
throw e;
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
throw new Exception(e);
try {
if (sReader != null) {
sReader.close();
}
if (bReader != null) {
bReader.close();
}
if (process != null) {
process.destroy();
}
} catch (Exception e) {
throw e;
}
}
return result;
......
......@@ -152,11 +152,11 @@ public class DataBuilder {
try {
outputs = m_commandUtils.runShell(cmd);
return convert2DataEntities(outputs);
} catch (Exception e) {
Cat.logError(e);
}
List<DataEntity> dataEntities = convert2DataEntities(outputs);
return dataEntities;
return new ArrayList<DataEntity>();
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册