[SNMP4J] DefaultUDPTransportMapping - java.lang.OutOfMemoryError

Yasen Simeonov(NeterraNMT) ysimeonov at neterra.net
Fri Aug 14 10:25:27 CEST 2009


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


-- 
Yasen Simeonov
Network Management Team
Neterra Ltd.
Sofia, Bulgaria
Phone:  +359 2 974 33 11
Fax:    +359 2 975 34 36
Mobile: +359 887 477 540
http://www.neterra.net



__________ Information from ESET NOD32 Antivirus, version of virus signature database 4254 (20090717) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com





More information about the SNMP4J mailing list