问题描述
Snmp4j开源包里自带了一个命令行Snmp工具,但使用过程发现用它来获取网络设备Snmp性能时失败.命令参数:-c!xmcT%^&8-v2c-Ot-t100010.4.3.1441.3.6.1.2.1.2.2.1.2.调试源码发现在Eclipse可以取到远端mib数据,但是打包放到批处理bat文件里调用就失败.跟踪org.snmp4j.tools.console.SnmpRequest.java发现下面代码中的synchronized(counter)同步块在批处理执行时失效,直接线程中断退出了。请教为何在Eclipse可以执行的得到结果,在批处理里执行却不行?publicvoidtable()throwsIOException{Snmpsnmp=createSnmpSession();this.target=createTarget();target.setVersion(version);target.setAddress(address);target.setRetries(retries);target.setTimeout(timeout);snmp.listen();TableUtilstableUtils=newTableUtils(snmp,this);tableUtils.setMaxNumRowsPerPDU(maxRepetitions);Counter32counter=newCounter32();OID[]columns=newOID[vbs.size()];for(inti=0;i<columns.length;i++){columns[i]=((VariableBinding)vbs.get(i)).getOid();}longstartTime=System.currentTimeMillis();synchronized(counter){TableListenerlistener;if(operation==TABLE){listener=newTextTableListener();}else{listener=newCVSTableListener(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(InterruptedExceptionex){Thread.currentThread().interrupt();}}//System.out.println("Tablereceivedin"+//(System.currentTimeMillis()-startTime)+"milliseconds.");snmp.close();}