[SNMP4J] Snmp Async Thread Pool

Frank Fock fock at agentpp.com
Mon Jul 16 23:40:07 CEST 2007


Hi Ryan,

You know that your are using a totally untested
intermediate version of SNMP4J? The code you quote
is from the SNMP4J 2.0 development version which
is based on JDK 1.5 (generics, enums, and
java.util.concurrent). I would not use that version
for anything, but good to hear that it works
in some way ;-)

Best regards,
Frank

Smith, Ryan wrote:
> I figured it out.....
> You call snmp.close(); 
> 
> DOH! 
> 
> Thanks for the help Sean, and thanks for listening everyone else :)
> 
> Snmp.java does make a threadPool of size 10 by the way:
> // Timer for retrying pending requests
>     private ScheduledThreadPoolExecutor executor = new
> ScheduledThreadPoolExecutor(10);
> 
> 
> -Ryan
>  
> 
> -----Original Message-----
> From: snmp4j-bounces at agentpp.org [mailto:snmp4j-bounces at agentpp.org] On
> Behalf Of Smith, Ryan
> Sent: Monday, July 16, 2007 3:05 PM
> To: Gibbons, Sean
> Cc: snmp4j at agentpp.org
> Subject: RE: [SNMP4J] Snmp Async Thread Pool
> 
> I found it, SNMP4J isn't making the threaded pool directly, but it is
> calling Java API code that makes the threadedpool,  So it seems that
> design-wise, snmp4j *should* include a method to control this ThreadPool
> functionality.
> 
> Here's what I have so far:
> I get to line 803 in Snmp.java:
> executor.schedule(request, delay, TimeUnit.MILLISECONDS); 
> 
> If you step into this method, it calls ScheduledThreadPoolExecutor's:
>     public ScheduledFuture<?> schedule(Runnable command, long delay,
> TimeUnit unit)
> 
> And this method calls:
>     private void delayedExecute(Runnable command)
> 
> This is the method that creates the ThreadPool from the initial example.
> 
> It is a java method in package java.util.concurrent;
> 
>     /**
>      * Specialized variant of ThreadPoolExecutor.execute for delayed
> tasks.
>      */
>     private void delayedExecute(Runnable command) {
>         if (isShutdown()) {
>             reject(command);
>             return;
>         }
>         // Prestart a thread if necessary. We cannot prestart it
>         // running the task because the task (probably) shouldn't be
>         // run yet, so thread will just idle until delay elapses.
>         if (getPoolSize() < getCorePoolSize())
>             prestartCoreThread();
>             
>         super.getQueue().add(command);
>     }
> 
> 
> Now, before I get all into this, any one got any ideas how to gracefully
> shutdown this thread pool?
> Thanks for the help so far.
> -Ryan
> 
> 
> -----Original Message-----
> From: Gibbons, Sean [mailto:Sean.Gibbons at trueposition.com]
> Sent: Monday, July 16, 2007 2:51 PM
> To: Smith, Ryan
> Cc: snmp4j at agentpp.org
> Subject: RE: [SNMP4J] Snmp Async Thread Pool
> 
> Just to append to what I said earlier, since I noticed something.  If
> you are using a multi threaded dispatcher, you have to pass the thread
> pool as part of the constructor.  So I guess you are responsible for
> cancelling it. 
> 
> I know you're not using the multi threaded dispatcher.  But my previous
> statement was sorta wrong.  I still don't see where that thread pool is
> coming from.  According to eclipse, a threadpool object is created in
> the SNMP4j api only in the listen() method of the SnmpRequest class.  
> 
> If you are using eclipse or something, I'd run a query to see where the
> threadpool object is being created in your code.  And make sure that
> pool gets closed on exit.
> 
> -----Original Message-----
> From: Smith, Ryan [mailto:rsmith at shsolutions.com]
> Sent: Monday, July 16, 2007 2:39 PM
> To: Gibbons, Sean
> Cc: snmp4j at agentpp.org
> Subject: RE: [SNMP4J] Snmp Async Thread Pool
> 
> 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
> 
> 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.
> 
> 
> _______________________________________________
> SNMP4J mailing list
> SNMP4J at agentpp.org
> http://lists.agentpp.org/mailman/listinfo/snmp4j
> _______________________________________________
> 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