FW: [SNMP4J] Concurrency Exception
Marco Matchefts
mmatchefts at cesura.com
Mon Feb 6 23:09:48 CET 2006
I think I found the problem. When I close the connection,
Snmp::close calls the ::onResponse callback on all outstanding
requests. The first thing I do in the ::onResponse callback
is invoke the following function. The javadocs mentioned we
need to do this to prevent a memory leak... Also if we don't
do this, I've been getting multiple callbacks.
( (Snmp) responseEvent.getSource()).cancel(responseEvent.getRequest(),
this);
So, the Snmp::cancel function modifies the pendingRequests hashtable,
which causes the iterator in the ::close fcn to go bad. Hence, the
concurrency exception.
So, under what scenarios should we be calling the
::cancel to prevent the memory leak? Should we call ::cancel for
all response events except those that throw an InterruptedException?
Thanks for the advice...
--Marco
-----Original Message-----
From: snmp4j-bounces at agentpp.org [mailto:snmp4j-bounces at agentpp.org] On
Behalf Of Marco Matchefts
Sent: Monday, February 06, 2006 2:48 PM
To: snmp4j at agentpp.org
Subject: [SNMP4J] Concurrency Exception
I have a multithreaded app. I am currently getting a concurrency
exception inside the stack
in the Snmp::close function. The stack trace is below. One thread of
my app is closing the
Snmp::connection. Another thread may have just sent a request.
Synchronization
should prevent both from happing at the same time. But I am getting the
following
exception:
2006-02-06 14:37:02,225 WARN DataCollectorTask sendRequest
failure:java.util.ConcurrentModificationException
2006-02-06 14:37:02,225 DEBUG DataCollectorTask sendRequest exception:
java.util.ConcurrentModificationException
at java.util.Hashtable$Enumerator.next(Unknown Source)
at org.snmp4j.Snmp.close(Snmp.java:430)
at
com.vieo.management.snmp.SNMP4jSessionFactory$SessionAdapter.close(SNMP4
jSessionFactory.java:231)
at
com.vieo.management.snmp.SNMP4jSessionFactory$SessionAdapter.send(SNMP4j
SessionFactory.java:266)
at
com.vieo.management.snmp.DataCollectorTask.sendRequests(DataCollectorTas
k.java:169)
at
com.vieo.management.snmp.DataCollectorTask.collectReadings(DataCollector
Task.java:122)
at
com.vieo.management.snmp.DataCollectorTask.run(DataCollectorTask.java:30
0)
at
com.vieo.util.TaskScheduler$TaskQueue$ScheduledTask.run(TaskScheduler.ja
va:1056)
at com.vieo.util.ThreadPool$TaskRunner.run(ThreadPool.java:212)
at java.lang.Thread.run(Unknown Source)
I see that the pendingRequests is just a plain Hashtable. By chance is
there another thread
doing something on the pendingRequests hashtable while I am closing the
thread?
Any insight would be very helpful. Thanks.
--Marco
_______________________________________________
SNMP4J mailing list
SNMP4J at agentpp.org
http://lists.agentpp.org/mailman/listinfo/snmp4j
More information about the SNMP4J
mailing list