No, the close() method should be called only when the Snmp instance will never again process SNMP messages.
Frank On 08.03.2011 23:49, Giuseppe Sarno wrote: > Thanks, > > So should smnp.close() not be invoked when the snmp object is reused or > should it still be called ? > > > -----Original Message----- > From: [email protected] [mailto:[email protected]] On > Behalf Of Frank Fock > Sent: 08 March 2011 22:34 > To: [email protected] > Subject: Re: [SNMP4J] Snmp object reuse. > > Hi, > > You should reuse a Snmp instance for subsequent requests. > Creating and closing/destroying it for each request is overkill and > guarantees bad performance and other issues on OS level (running out of > ports, etc.) > > Best regards > Frank > > On 08.03.2011 23:18, Giuseppe Sarno wrote: >> Hello, >> I seem to have memory issue using the code below. I seem to have a large >> number of snmp instances (almost 1 per message been sent).Same more the >> messageDispacherImpl. >> I am wondering whether the snmp should be cached instead of created every >> single time. Is it enough to call snmp.close() ? >> >> Thanks. >> >> >> -----Original Message----- >> From: [email protected] [mailto:[email protected]] >> On Behalf Of Giuseppe Sarno >> Sent: 02 March 2011 22:21 >> To: [email protected] >> Subject: [SNMP4J] Setting Local port in DefaultUdpTransport causes null >> responses. >> >> Hello, >> new to SNMP and to this API. >> I am trying to use code snippet from >> http://www.snmp4j.org/doc/org/snmp4j/Snmp.html to build a SNMP manager that >> sends a SET between 2 nodes (SNMP4J 1.11.2). >> I use Java executors to invoke the task that will actually perform the work. >> I noticed that this works ok if I don't set the LocalPort in the UDP >> transport. >> I actually would like to fix the port to a specific value so I set it in the >> transport constructor. Unfortunately after this change the PDU response is >> always "null". >> Messages are correctly sent and replied back (checked with wireshark). I am >> not too sure whether there is any threading issue as the transport is bound >> to a specific port or simply my code is not correct. >> >> Can anybody please let me know if there is any problem with this approach >> and what the problme could be ? >> >> Thanks. >> >> >> The task will: >> >> 1) Creates DefaultUdpTransportMapping (note I need to set the local >> port and I to add to set the option "reuse" to true as I was getting >> bind exception) >> >> DefaultUdpTransportMapping(new >> UdpAddress(InetAddress.getLocalHost(),localport),true); >> >> 2) Creates community target. >> >> CommunityTarget comtarget = new CommunityTarget(); >> comtarget.setCommunity(new OctetString(community)); >> comtarget.setVersion(snmpVersion); >> comtarget.setAddress(new UdpAddress(ip + "/" + port)); >> comtarget.setRetries(0); >> comtarget.setTimeout(100); >> >> 3) Creates a PDU >> >> PDU pdu = new PDU(); >> >> 4) Creates SNMP with the UDP transport (above) >> >> Snmp snmp = new Snmp(this.getUDPTransport()); >> >> 5) Sends and wait for the resposne: >> >> ResponseEvent response = snmp.set(pdu, comtarget); >> // Process Agent Response >> if (response != null) >> { >> >> do work<< >> } >> >> Excecutor that wraps the code above: >> >> ExecutorService threadExecutor = Executors.newFixedThreadPool( Data.POOL ); >> for ( int i=1;i<=100000;i++) { RunnableTask t = new >> RunnableTask(Integer.toString(i)); >> threadExecutor.execute(t); >> } >> threadExecutor.shutdown(); // shutdown worker threads } >> _______________________________________________ >> SNMP4J mailing list >> [email protected] >> http://lists.agentpp.org/mailman/listinfo/snmp4j >> _______________________________________________ >> SNMP4J mailing list >> [email protected] >> http://lists.agentpp.org/mailman/listinfo/snmp4j > -- AGENT++ http://www.agentpp.com http://www.snmp4j.com http://www.mibexplorer.com http://www.mibdesigner.com _______________________________________________ SNMP4J mailing list [email protected] http://lists.agentpp.org/mailman/listinfo/snmp4j
