[SNMP4J] Snmp.close() and async requests

Marek Zawirski marek.zawirski at gmail.com
Thu Jul 26 18:37:26 CEST 2007


Hello group!
I use snmp4j for asynchronous SNMP requests/GETs. I've observed strange
behaviour of Snmp.close() method. It may throw, and in my application it
throws indeed, ConcurrentModificationException during iteration over
pendingRequests - beacouse of possible concurrent Snmp.cancel() calls
from ResponseListeners. This occurs when they are some pending requests
when the close() is called (it's easy to achieve for test purpose by
communicating with non existing agent -> timeout), these requests get
responses during close() execution and their listeners call cancel().
In my app ResponseListeners  received ResponseEvent with
InterruptedException (sent from close()...), which resulted in
ConcurrentModificationException after cancel(), but in general they
could receive any other ResponseEvent that can't be filtered so easy.

This problem could be resolved at application level, but IMHO it
could/should be done easier at library level, at least by doing clone of
pendingRequests Hashtable before iterating over it, or by synchronizing
whole access to this structure.
What do you think? Or did I miss something?

Thanks for nice library!
Best Regards,
-- 
Marek Zawirski [zawir]




More information about the SNMP4J mailing list