[SNMP4J] DefaultUDPTransportMapping - java.lang.OutOfMemoryError
Frank Fock
fock at agentpp.com
Fri Aug 14 10:46:45 CEST 2009
Hi Yasen,
By creating a TransportMapping you use 1MB of Memory
by default (with standard Java stack size), because each
TransportMapping uses its own Thread.
Please keep in mind, a TransportMapping is a transport
mapping and *not* a connection! Thus, to access millions of
UDP target addresses, you need only a single (UDP) transport
mapping.
Best regards,
Frank
Yasen Simeonov(NeterraNMT) schrieb:
> Hi Frank,
>
> I have a List that contain objects<PortCrc> with info about devices and
> ifDesc,
> they are about 100.I am trying to get errors from the ports on every device.
> Unfortunately i have next runtime error:
>
> Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
> at
> org.snmp4j.transport.DefaultUdpTransportMapping$ListenThread.<init>(DefaultUdpTransportMapping.java:286)
> at
> org.snmp4j.transport.DefaultUdpTransportMapping.listen(DefaultUdpTransportMapping.java:165)
> at org.snmp4j.Snmp.listen(Snmp.java:390)
> at
> yasen.snmp.tools.SnmpV2cGetNext.getValueFromOID(SnmpV2cGetNext.java:60)
> at Test.main(Test.java:94)
>
>
>
>
>
>
> Next is my code that use the SNMP class.
>
> for (int i = 0; i < portCrcList.size(); i++) {
> PortCrc portCrc = (PortCrc) portCrcList.get(i);
> Device dev = portCrc.getDevice();
> SnmpV2cGetNext obj = new SnmpV2cGetNext(dev.getIp(), dev
> .getSnmp_ro());
> String c = null;
> try {
> c = obj.getValueFromOID("1.3.6.1.2.1.2.2.1.14."
> + portCrc.getIfdesc());
> } catch (IOException e) {
> e.printStackTrace();
> }
> long crc = Long.parseLong(c.trim());
>
> System.out.println("ID: " + portCrc.getDev_id() + ", DevName: "
> + portCrc.getDevname() + ", ifDesc: " +
> portCrc.getIfdesc()
> + ", Port: " + portCrc.getPort() + ", CRC: " + crc);
> }
> }
>
>
> And the SnmpV2cGetNext.java is:
>
>
> public class SnmpV2cGetNext {
>
> TransportMapping transport;
> Address targetAddress;
> CommunityTarget target;
>
> public SnmpV2cGetNext(String ip, String community){
> try {
> targetAddress = GenericAddress.parse("udp:" + ip + "/161");
> transport = new DefaultUdpTransportMapping();
> target = new CommunityTarget();
> target.setCommunity(new OctetString(community));
> target.setAddress(targetAddress);
> target.setRetries(3);
> target.setTimeout(2000);
> target.setVersion(SnmpConstants.version2c);
> } catch (IOException ex) {
>
> java.util.logging.Logger.getLogger(SnmpV2cGetNext.class.getName()).log(java.util.logging.Level.SEVERE,
> null, ex);
> }
>
> }
>
> public String getValueFromOID( String oid) throws IOException{
> PDU pdu = new PDU();
> pdu.setType(PDU.GETNEXT);
> pdu.add(new VariableBinding(new OID(oid)));
> pdu.setNonRepeaters(0);
> Snmp snmp = new Snmp(transport);
> snmp.listen();
> ResponseEvent responseEvent = snmp.send(pdu, target);
> PDU responsePDU = responseEvent.getResponse();
> VariableBinding var=new VariableBinding();
> var=(VariableBinding)
> responsePDU.getVariableBindings().elements().nextElement();
> return var.getVariable().toString();
> }
>
> }
>
> If you have idea how can i avoid this Java heap overflow, please help me.
>
> Best regards,
> Yasen
>
>
>
More information about the SNMP4J
mailing list