[SNMP4J] About IllegalStateException

=??b?wfi9wrn8?= steve at nextdata.co.kr
Mon Dec 18 05:20:24 CET 2006


Hi,

1. About the IllegalStateException

I'm not have the source code of using timer now, so I can't reproduce the case, sorry.

2. About the problems related to Architecture.

When using the Timer and  TimerTask you should create the TimerTask
to watch somtimg. That means sometimes it can cause java OutOfMemoryError.
And the another things that I am worring about is exceptional case(such as IllegalStateException) 
always happen when using timer signaling & canceling by logical problems of developers who using the timer.
And the another reason is the interval was not correct with running it under heavy load.

3. About watch-up Thread

If the timer sleep interval is the issue, someone who use it can adjust it.
The important thing is sleeping it within some period of time so that
the CPU can process another instructions and get the results that expected.

--------------------- Orignal Message ---------------------
From: Frank Fock
Subject: Re: [SNMP4J] About IllegalStateException



Hi,

? wrote:
> $)CHi,
> 
> I have interested the problems you wrote since I had found the behavior
> of the Snmp class something incorrect.

Could you provide details? Or is it the IllegalStateException issue?

> In my case, I wrote a new class send PDUs to target and process the timeout
> because I made a conclusion that the JAVA timer itself can produce a problem
> on resource handling when we try to make up well organized software architecture.

Why should be using java.util.Timer an architectural problem?

> And finally I use very little time slice of CPU and have succeeded to get timeout result 
> under 5msec tolerance.

Without using a real-time Java system such time specifications
have no significance. Using a polling Thread that sleeps
unconditional either uses more CPU cycles than required or
waste responsiveness by waiting.

Best regards,
Frank

> 
> My aproach is use just another one watch up thread and polling the 
> SNMP responses of all PDUs we have send.
> 
> the part of source code
> 
> while(true)
> {
> try
> {
> sleep(0,1);
> 
> for(..) // monitoring results of..
> {
> //some code stuffs that watch up
> ..
> sleep(0,1);
> }
> }
> }
> 
> I hope my approch can be helpful to you.
> 
> Regards,
> Steve Jin 
> 
> --------------------- Original Messages ---------------------
> From: snmp4j-request at agentpp.orgSubject: SNMP4J Digest, Vol 35, Issue 9
> Subject: 
> 
> 
> 
> Send SNMP4J mailing list submissions to
> snmp4j at agentpp.org
> 
> To subscribe or unsubscribe via the World Wide Web, visit
> http://lists.agentpp.org/mailman/listinfo/snmp4j
> or, via email, send a message with subject or body 'help' to
> snmp4j-request at agentpp.org
> 
> You can reach the person managing the list at
> snmp4j-owner at agentpp.org
> 
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of SNMP4J digest..."
> 
> 
> Today's Topics:
> 
> 1. IllegalStateException in Snmp.send() (Alberto)
> 2. Virtual SNMPv3 Server (Keary Parinis)
> 3. CHANGE OF THE SENDER IP (RC_Insignia)
> 4. Re: IllegalStateException in Snmp.send() (Frank Fock)
> 5. Re: CHANGE OF THE SENDER IP (Frank Fock)
> 6. Re: Virtual SNMPv3 Server (Frank Fock)
> 7. Re: Virtual SNMPv3 Server (Keary Parinis)
> 8. R: Re: [SNMP4J] IllegalStateException in Snmp.send() (Alberto)
> 9. Re: R: Re: [SNMP4J] IllegalStateException in Snmp.send()
> (Fabian Nart)
> 
> 
> ----------------------------------------------------------------------
> 
> Message: 1
> Date: Wed, 13 Dec 2006 16:38:28 +0100 (CET)
> From: Alberto 
> Subject: [SNMP4J] IllegalStateException in Snmp.send()
> To: snmp4j at agentpp.org
> Message-ID:
> <32705453.1240591166024308212.JavaMail.defaultUser at defaultHost>
> Content-Type: text/plain;charset="UTF-8"
> 
> 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
> 
> 
> ------------------------------
> 
> Message: 2
> Date: Wed, 13 Dec 2006 08:13:54 -0800 (PST)
> From: Keary Parinis 
> Subject: [SNMP4J] Virtual SNMPv3 Server
> To: snmp4j at agentpp.org
> Message-ID: <20061213161354.5639.qmail at web60715.mail.yahoo.com>
> Content-Type: text/plain; charset=ascii
> 
> Hi,
> 
> I use a java app at work that collects router information using SNMP4J and we are currently using SNMP version 2. We will upgrade to version 3 shortly. I see the code example for version 3 in the Java docs. I would like to re-code my java app and test before the upgrade. Does anyone know how to create a virtual SNMPv3 server with SNMP4J? I just need something that will accept USM authentication and reply to a get request. I think I can create something simple with a ServerSocket running on port 162. Is there something out there that does this. I had no luck with google for the past few hours. Thanks in advance.
> 
> 
> K E
> 
> ------------------------------
> 
> Message: 3
> Date: Wed, 13 Dec 2006 11:55:45 -0400
> From: "RC_Insignia" 
> Subject: [SNMP4J] CHANGE OF THE SENDER IP
> To: 
> Message-ID:
> 
> Content-Type: text/plain; charset="iso-8859-1"
> 
> In my computer I have 4 differents IP4s because VPN requisites I need to
> change the sender IP different from the localhost.
> How I can do that and send the trps trough a specific IP in my machine ?
> 
> Thanks in advance,
> 
> Ricardo Carrillo
> 
> 
> 
> ------------------------------
> 
> Message: 4
> Date: Thu, 14 Dec 2006 00:55:52 +0100
> From: Frank Fock 
> Subject: Re: [SNMP4J] IllegalStateException in Snmp.send()
> To: Alberto 
> Cc: snmp4j at agentpp.org
> Message-ID: <45809308.105 at agentpp.com>
> Content-Type: text/plain; charset=UTF-8; format=flowed
> 
> 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