Eclipse里运行正常,放到批处理就失败,求教?
Snmp4j开源包里自带了一个命令行Snmp工具,但使用过程发现用它来获取网络设备Snmp性能时失败.命令参数:-c !xmcT%^&8 -v 2c -Ot -t 1000 10.4.3.144 1.3.6.1.2.1.2.2.1.2.
调试源码发现在Eclipse可以取到远端mib数据,但是打包放到 批处理bat文件里调用就失败.
跟踪org.snmp4j.tools.console.SnmpRequest.java 发现 下面代码中的synchronized (counter) 同步块在批处理执行时失效,直接线程中断退出了。
请教为何在Eclipse可以执行的得到结果,在批处理里执行却不行?
public void table() throws IOException {
Snmp snmp = createSnmpSession();
this.target = createTarget();
target.setVersion(version);
target.setAddress(address);
target.setRetries(retries);
target.setTimeout(timeout);
snmp.listen();
TableUtils tableUtils = new TableUtils(snmp, this);
tableUtils.setMaxNumRowsPerPDU(maxRepetitions);
Counter32 counter = new Counter32();
OID[] columns = new OID[vbs.size()];
for (int i=0; i<columns.length; i++) {
columns[i] = ((VariableBinding)vbs.get(i)).getOid();
}
long startTime = System.currentTimeMillis();
synchronized (counter) {
TableListener listener;
if (operation == TABLE) {
listener = new TextTableListener();
}
else {
listener = new CVSTableListener(System.currentTimeMillis());
}
if (useDenseTableOperation) {
tableUtils.getDenseTable(target, columns, listener, counter,
lowerBoundIndex, upperBoundIndex);
}
else {
tableUtils.getTable(target, columns, listener, counter,
lowerBoundIndex, upperBoundIndex);
}
try {
counter.wait(timeout);
}
catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}
}
//System.out.println("Table received in "+
// (System.currentTimeMillis()-startTime)+" milliseconds.");
snmp.close();
}
调试源码发现在Eclipse可以取到远端mib数据,但是打包放到 批处理bat文件里调用就失败.
跟踪org.snmp4j.tools.console.SnmpRequest.java 发现 下面代码中的synchronized (counter) 同步块在批处理执行时失效,直接线程中断退出了。
请教为何在Eclipse可以执行的得到结果,在批处理里执行却不行?
public void table() throws IOException {
Snmp snmp = createSnmpSession();
this.target = createTarget();
target.setVersion(version);
target.setAddress(address);
target.setRetries(retries);
target.setTimeout(timeout);
snmp.listen();
TableUtils tableUtils = new TableUtils(snmp, this);
tableUtils.setMaxNumRowsPerPDU(maxRepetitions);
Counter32 counter = new Counter32();
OID[] columns = new OID[vbs.size()];
for (int i=0; i<columns.length; i++) {
columns[i] = ((VariableBinding)vbs.get(i)).getOid();
}
long startTime = System.currentTimeMillis();
synchronized (counter) {
TableListener listener;
if (operation == TABLE) {
listener = new TextTableListener();
}
else {
listener = new CVSTableListener(System.currentTimeMillis());
}
if (useDenseTableOperation) {
tableUtils.getDenseTable(target, columns, listener, counter,
lowerBoundIndex, upperBoundIndex);
}
else {
tableUtils.getTable(target, columns, listener, counter,
lowerBoundIndex, upperBoundIndex);
}
try {
counter.wait(timeout);
}
catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}
}
//System.out.println("Table received in "+
// (System.currentTimeMillis()-startTime)+" milliseconds.");
snmp.close();
}
...全文
相关推荐
IDEA运行导入的javaweb项目tomcat正常,但是运行失败404问题
主要介绍了IDEA运行导入的javaweb项目tomcat正常但是运行失败404问题,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
Eclipse中Tomcat启动失败的解决方案
( Eclipse中Tomcat启动失败的解决方案.txt
Eclipse运行时提示failed to create the java virtual machine
Eclipse运行时提示failed to create the java virtual machine 解决方法方法
运行eclipse提示JVM错误的解决
运行eclipse提示JVM错误的解决方法
在AndroidStudio中导入eclipse项目后如何运行
将eclipse中的android项目导入到AndroidStudio中,使其运行的操作步骤


Java SE
