[SNMP4J] SNMP4J multiple threads
Frank Fock
fock at agentpp.com
Fri Jun 29 20:40:26 CEST 2007
Hello Francis,
From your code it seems that you create a
transport mapping and Snmp instance for each
request. Although that can be done, I strongly
do not recommend it for frequent requests,
because there is a lot overhead in creating
a transport mapping and a Snmp instance.
You should use both for application life time,
if possible.
In any case, call Snmp.close() when you no longer
want to use a Snmp instance.
Best regards,
Frank
Francis LIMOUSY wrote:
>
> Hello,
>
> I'm using snmp4j in a threaded application, fetching synchronously data.
> I have this problem: threads don't seem to be de-allocated.
> I have plenty of UdpDefaultTransportMapping stacking into memory until
> the application crash (out of system resources).
>
> My question is: is this a Thread issue or a snmp4j issue ?
>
> My code is quite simple for the moment, the created threads run the
> following code:
>
> try{
> TransportMapping transport = new DefaultUdpTransportMapping();
> Snmp snmp = new Snmp(transport);
> PDU pdu = new PDU();
>
> for(String oid : oids){
> pdu.add(new VariableBinding(new OID(oid)));
> }
>
> pdu.setType(PDU.GETNEXT);
> CommunityTarget target = new CommunityTarget();
> target.setCommunity(new OctetString(community));
> target.setAddress(targetAddress);
> target.setVersion(Integer.parseInt(version));
> transport.listen();
> ResponseEvent response = snmp.send(pdu,
> target); if (response.getResponse() ==
> null) {
> System.out.println("Timeout");
> }
> else { //handle response
> (...)
> }
> }
>
>
>
> I guess the problem occur here :
> ResponseEvent response = snmp.send(pdu, target);
>
> which is synchronous if I get the examples well.
> So I guess some of my threads are blocking here, aren't they ?
> If so, how can I specify a timeout ? Is there another way of doing this ?
>
> Thanks for any help on this problem.
>
> I'm using SNMP protocol v1, Java 1.5 on a windows environment
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> SNMP4J mailing list
> SNMP4J at agentpp.org
> http://lists.agentpp.org/mailman/listinfo/snmp4j
--
AGENT++
http://www.agentpp.com
http://www.mibexplorer.com
http://www.mibdesigner.com
More information about the SNMP4J
mailing list