Chinaunix

标题: Eclipse里运行正常,放到批处理就失败,求教? [打印本页]

作者: microchu    时间: 2011-07-03 10:10
标题: 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 = ((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();
  }
作者: zhblue    时间: 2011-07-03 12:16
直觉说:classpath缺包




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2