[SNMP4J] Snmp Async Thread Pool

Smith, Ryan rsmith at shsolutions.com
Mon Jul 16 20:39:12 CEST 2007


Sean,
Thanks for the heads up, that's good to know.  As far as I know though,
I'm not using MultiThreadedMessageDispatcher.  I just sent out my
example on the mailing list taken straight from the SNMP.html javadoc
example: http://www.snmp4j.org/doc/org/snmp4j/Snmp.html
With some slight modifications to get it to run.

Ill keep digging around, I wish this example was using the threadPool,
so I could call .shutdown() on it.

Thanks,
-Ryan

-----Original Message-----
From: Gibbons, Sean [mailto:Sean.Gibbons at trueposition.com] 
Sent: Monday, July 16, 2007 1:31 PM
To: Smith, Ryan; Frank Fock
Cc: snmp4j at agentpp.org
Subject: RE: [SNMP4J] Snmp Async Thread Pool

I think it's a potential bug in the code.  If you are using a
MultiThreadedMessageDispatcher object, it creates the threadpool, and
runs it.  But there doesn't seem to be a function in the
MultiThradedMessageDispatcher class that will cancel the ThreadPool.  In
my own program, I made my own multithreaded dispatcher with a stop()
method that calls the stop() method in the threadpool.  Eclipse does not
show any calls to the threadpool stop() method within the SNMP4j API.  

-----Original Message-----
From: snmp4j-bounces at agentpp.org [mailto:snmp4j-bounces at agentpp.org] On
Behalf Of Smith, Ryan
Sent: Monday, July 16, 2007 1:16 PM
To: Frank Fock
Cc: snmp4j at agentpp.org
Subject: RE: [SNMP4J] Snmp Async Thread Pool

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

_______________________________________________
SNMP4J mailing list
SNMP4J at agentpp.org
http://lists.agentpp.org/mailman/listinfo/snmp4j


Confidentiality Notice
This e-mail (including any attachments) is intended only for the
recipients named above. It may contain confidential or privileged
information and should not be read, copied or otherwise used by any
other person. If you are not a named recipient, please notify the sender
of that fact and delete the e-mail from your system.





More information about the SNMP4J mailing list