I have a thread that does a SNMP get request periodically in a loop.
Interrupting the thread should cause the loop to stop, but doesn't.
Here's some pseudo-code:

public class SnmpBug  {
                
        public void start() throws IOException {
                TransportMapping transport = new DefaultUdpTransportMapping();
                transport.listen();
                final Snmp snmp = new Snmp(transport);

                        thread = new Thread() {
                                @Override
                                public void run() {
                                        try {
                                                while (!isInterrupted()) {
                                                        ResponseEvent response 
= snmp.get(requestPdu, target);
                                                        // handle response

                                                        Thread.sleep(5000);
                                                }
                                        } catch (InterruptedException ie) {
                                                // interrupted, return
                                        }
                                        // this line is never reached
                                }
                        };
                        thread.start();
                
        }

        public void stop() {
                if (thread != null) {
                        thread.interrupt();
                }
        }
}

The bug is in Snmp.java line 820.  The library method could throw
InterruptedException, or set interrupted to true.

A good article on how to handle InterruptedException is here:
http://www.ibm.com/developerworks/java/library/j-jtp05236.html


-- 
Jonathan Louie <[EMAIL PROTECTED]>
 http://www.eff.org/
_______________________________________________
SNMP4J mailing list
[email protected]
http://lists.agentpp.org/mailman/listinfo/snmp4j

Reply via email to