[SNMP4J] Snmp Async Thread Pool
Smith, Ryan
rsmith at shsolutions.com
Mon Jul 16 19:15:48 CEST 2007
Thanks Frank,
I think maybe my language was misleading. I'm not sure there's a thread
pool per se ,
So please allow me to make my test case simpler here:
I am using the sample code from:
http://www.snmp4j.org/doc/org/snmp4j/Snmp.html
"An asynchronous SNMPv1 request is sent by the following code:
// setting up target
CommunityTarget target = new CommunityTarget();
target.setCommunity(new OctetString("public"));
target.setAddress(targetAddress);
target.setRetries(2);
target.setTimeout(1500);
target.setVersion(SnmpConstants.version1);
// creating PDU
PDU pdu = new PDU();
pdu.add(new VariableBinding(new OID(new int[] {1,3,6,1,2,1,1,1})));
pdu.add(new VariableBinding(new OID(new int[] {1,3,6,1,2,1,1,2})));
pdu.setType(PDU.GETNEXT);
// sending request
ResponseListener listener = new ResponseListener() {
public void onResponse(ResponseEvent event) {
// Always cancel async request when response has been received
// otherwise a memory leak is created! Not canceling a request
// immediately can be useful when sending a request to a
broadcast
// address.
((Snmp)event.getSource()).cancel(event.getRequest(), this);
System.out.println("Received response PDU is:
"+event.getResponse());
}
};
snmp.sendPDU(pdu, target, null, listener);
"
And it all seems to work, I can see the SNMP Packets being sent over the
network via Wireshark, and all the VariableBindings are there.
But I noticed in this example, my *main* thread exists, while the async
request seems to be keeping a thread alive for a long time (forever?)
I assumed there was a thread pool of 10 b/c in my Eclipse debug window,
10 threads get created (no more). A new thread gets created for each
"retry" ( I have mine set to 3 retries ) So by the 4th Async message I
send, there are 10 threads running there, waiting, while the main thread
is already done. So, I think I over complicated the actual question I
was trying to ask. :)
Im just wanting to know, why after I call the async method, my main
thread can die, but the async thread stays alive? And how do I
Interrupt or notify all the waiting threads to exit. Thank you.
-Ryan
-----Original Message-----
From: Frank Fock [mailto:fock at agentpp.com]
Sent: Monday, July 16, 2007 1:00 PM
To: Smith, Ryan
Cc: snmp4j at agentpp.org
Subject: Re: [SNMP4J] Snmp Async Thread Pool
Hi Ryan,
Snmp does not use any ThreadPool so I think your problem is caused by
the application not the SNMP4J API.
Best regards,
Frank
Smith, Ryan wrote:
>
>
> Hello,
>
> When I try to send 100 PDU() objects via the .send() or .inform()
> methods (async) I see that a thread pool of up to 10 threads are
> created.
>
> When my program is finished running, the main thread ends, but the
> threads in the thread pool remain running, (all 10) causing the
> application to hang (not exit). I'm calling: ((Snmp)
> event.getSource()).cancel(event.getRequest(), this) in the callback
> method.
> I configure the snmp class to timeout sends after 5 seconds and retry
> 3 times before giving up.
>
> Now, the snmp Manager I'm trying to send to is on udp:192.0.1.123:162
> - This machine doesn't exist. So the host is unreachable and all the
> requests timeout, the only problem is that the threads aren't dying
> as I expect they should. I'm not sure what else I'm missing here, any
> ideas?
>
> Thank you,
> -Ryan
> _______________________________________________
> 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