[SNMP4J] IllegalStateException in Snmp.send()

Frank Fock fock at agentpp.com
Thu Dec 14 00:55:52 CET 2006


Hello Alberto,

You wrote that you had to restart your application
in order to use your Snmp instance again after
having caught the error below. This indicates,
that the timer referred to in the exception,
had been canceled. That means that your code
somewhere called Snmp.close() while requests
where pending.

That is how it is supposed to work: If you close
the Snmp instance, then it is shutdown and
cannot be used again. You will need to instantiate
a new Snmp instance.

So please do not call Snmp.close() between two
queries!

Hope this helps.

Best regards,
Frank

Alberto wrote:
> Hello,
> I refer to the correction provided in v1.7.1 and described by Frank in email 
> below.
> Since I got the same problem in my project, I downloaded the SNMP4J version 
> 1.7.5 and reproduced the error with log4j logs enabled.
> Here the result (just reported the PduHandle with the problem, but if you need 
> I have the complete logs):
> 
> 13/12/2006 14:30:30:131 DEBUG [pool-10-thread-22] [Log4jLogAdapter.debug] New 
> pending request with handle PduHandle[1826954335]
> ...
> 13/12/2006 14:30:45:579 DEBUG [Timer-15] [Log4jLogAdapter.debug] Running 
> pending request (3 left) with handle: PduHandle[1826954335]
> ...
> 13/12/2006 14:31:00:587 DEBUG [Timer-15] [Log4jLogAdapter.debug] Running 
> pending request (2 left) with handle: PduHandle[1826954335]
> ...
> 13/12/2006 14:31:00:589 DEBUG [SNMPDriverDispatchPool.2] [Log4jLogAdapter.
> debug] Looking up pending request with handle PduHandle[1826954335]
> ...
> 13/12/2006 14:31:00:591 ERROR [Timer-15] [Log4jLogAdapter.error] Failed to 
> process pending request PduHandle[1826954335] because Task already scheduled or 
> cancelled
> java.lang.IllegalStateException: Task already scheduled or cancelled
>         at java.util.Timer.sched(Timer.java:358)
>         at java.util.Timer.schedule(Timer.java:170)
>         at org.snmp4j.Snmp$PendingRequest.run(Snmp.java:1426)
>         at java.util.TimerThread.mainLoop(Timer.java:512)
>         at java.util.TimerThread.run(Timer.java:462)
> ...
> 13/12/2006 14:31:00:590 DEBUG [pool-10-thread-22] [Log4jLogAdapter.debug] 
> Removed pending request with handle: PduHandle[1826954335]
> ...
> 
> It seems there is a relation between the time the Timer-15 is checking the 
> handle for the second time (14:31:00:587) and the time the answer comes (14:31:
> 00:589). They are really very closed one to the other.
> Maybe a synchronization problem among threads?
> 
> Of course, after Timer-15 thread dies, no Snmp primitive to the agent is 
> possible anymore and my application has to be restarted.
> 
> Can you help, please?
> Regards,
> Alberto
> 
> 
> Frank wrote:
> 
>> Hi Fabian,
>>
>> We can catch only a RuntimeException and rethrow it. I have
>> changed the code as follows for v1.7.1:
>>
>>      /**
>>       * run
>>       */
>>      public synchronized void run() {
>>        try {
>>          if ((!finished) && (retryCount > 0)) {
>> ...
>>          }
>>        }
>>        catch (RuntimeException ex) {
>>          logger.error("Failed to process pending request "+key+
>>                       " because"+ex.getMessage(), ex);
>>          throw ex;
>>        }
>>
>> Best regards,
>> Frank
>>
> 
> 
> --------------------
> Alberto Mascheroni
> Mob. +39-333-6314222
> _______________________________________________
> 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