[SNMP4J] problem when running snmp walk for a long time

YUAN Shuai vmlist at 126.com
Thu Jan 24 11:31:52 CET 2008


hi all, here is the situation:

In each thread, I put a snmp walk request in a while-loop, so that the walk can be done at every 0 and 30 second.

Nearly 60 threads are created, and after running for about 3 hours, I got the following error and my other running applications just got errors too such as 'dll error' :

Exception in thread "Thread-34" java.lang.OutOfMemoryError: unable to create new native thread
        at java.lang.Thread.start0(Native Method)
        at java.lang.Thread.start(Thread.java:597)
        at java.util.Timer.<init>(Timer.java:154)
        at java.util.Timer.<init>(Timer.java:122)
        at org.snmp4j.Snmp.<init>(Unknown Source)
        at org.snmp4j.Snmp.<init>(Unknown Source)
        at snmpacc.SNMPAccWalk.createSnmpSession(SNMPAccWalk.java:80)
        at snmpacc.SNMPAccWalk.walkLeaf(SNMPAccWalk.java:106)
        at scout.PERFWalker.run(PERFWalker.java:80)
        at java.lang.Thread.run(Thread.java:619)

and

java.net.SocketException: No buffer space available (maximum connections reached?): Socket creation failed
        at java.net.PlainDatagramSocketImpl.datagramSocketCreate(Native Method)
        at java.net.PlainDatagramSocketImpl.create(PlainDatagramSocketImpl.java:73)
        at java.net.DatagramSocket.createImpl(DatagramSocket.java:317)
        at java.net.DatagramSocket.<init>(DatagramSocket.java:208)
        at java.net.DatagramSocket.<init>(DatagramSocket.java:261)
        at java.net.DatagramSocket.<init>(DatagramSocket.java:234)
        at org.snmp4j.transport.DefaultUdpTransportMapping.<init>(Unknown Source)
        at snmpacc.SNMPAccWalk.createSnmpSession(SNMPAccWalk.java:79)
        at snmpacc.SNMPAccWalk.walkLeaf(SNMPAccWalk.java:106)
        at scout.PERFWalker.run(PERFWalker.java:80)
        at java.lang.Thread.run(Thread.java:619)

However I am sure to invoke the close() method, and the following is my walkLeaf():

    public String walkLeaf(String oid) throws IOException {
//        System.out.println("walk oid:" + oid);
        Address address = new UdpAddress(IPAddress.toString() + "/161");
        Snmp snmp = createSnmpSession();
        Target target = createTarget();
        target.setVersion(getVersion(Version));
        target.setAddress(address);
        target.setRetries(retries);
        target.setTimeout(timeout);
        target.setMaxSizeRequestPDU(65535);
        snmp.listen();
        PDU request = new PDU();
        request.setType(PDU.GET);
        request.add(new VariableBinding(new OID(oid)));
        
        PDU response = null;
        
        ResponseEvent responseEvent = snmp.send(request, target);
        if (responseEvent == null) {
            return "no response";
        }
        
        // receive the result
        response = responseEvent.getResponse();
        
        // close the connection
        snmp.close();
        snmp = null;
        
        if (response == null) {
            return "no response";
        }
        
        return new String(response.get(0).getVariable().toString());
    }

anyone get any idea dealing with this? THANK YOU!

vmape, 2008.01.24



More information about the SNMP4J mailing list