Eclipse里运行正常,放到批处理就失败,求教?

microchu microchu 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
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();
}



...全文
评论
收藏 已收藏
分享
返回顶部
microchu
Java SE 62,621 成员 307,251 内容