Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Strange IllegalStateException: "Timer already cancelled"

1,929 views
Skip to first unread message

Jacob Eliosoff

unread,
Oct 15, 2001, 2:23:28 PM10/15/01
to
I'm getting this exception in a class of mine which uses a
java.util.Timer. The thing is I'm not canceling the Timer. There's
no call to cancel() anywhere in my code.
I'm seeing this when running it in an applet in IE under Windows
2000. It's a recent version of IE using JDK 1.3. I start one applet,
close it, try to start another and get this exception. Both applets
refer to my ErrorChecker class with its static Timer object. Maybe
closing the first applet is causing objects in the Timer to be garbage
collected? According to the Timer source, garbage collection would
cause the thread to be stopped, via a "threadReaper" object's
finalize() method.
I'm just wondering if anyone has run into this before, or can see
how something in the chronology of applet garbage collection could
produce this exception.
I've been using Java heavily for six years.
Thanks folks!
-Jacob

---------- Stack trace ----------

java.lang.IllegalStateException: Timer already cancelled.
at java.util.Timer.sched(Unknown Source)
at java.util.Timer.scheduleAtFixedRate(Unknown Source)
at net.invisiblehand.util.ErrorChecker.addErrorSource(ErrorChecker.java:57)
...

- 1. What to do
- 1.a) What to believe
- 2. Do it

Paul Lutus

unread,
Oct 15, 2001, 2:33:59 PM10/15/01
to
"Jacob Eliosoff" <co...@invisiblehand.net> wrote in message
news:5c670dfa.01101...@posting.google.com...

Without seeing the code, who can say? Maybe there is a way to evaluate the
timer's state before trying to cancel it. Just at a glance, without reading
your code. :)

--
Paul Lutus
www.arachnoid.com


Jon Skeet

unread,
Oct 15, 2001, 2:48:53 PM10/15/01
to
Jacob Eliosoff <co...@invisiblehand.net> wrote:
> I'm getting this exception in a class of mine which uses a
> java.util.Timer. The thing is I'm not canceling the Timer. There's
> no call to cancel() anywhere in my code.
> I'm seeing this when running it in an applet in IE under Windows
> 2000. It's a recent version of IE using JDK 1.3. I start one applet,
> close it, try to start another and get this exception. Both applets
> refer to my ErrorChecker class with its static Timer object. Maybe
> closing the first applet is causing objects in the Timer to be garbage
> collected? According to the Timer source, garbage collection would
> cause the thread to be stopped, via a "threadReaper" object's
> finalize() method.
> I'm just wondering if anyone has run into this before, or can see
> how something in the chronology of applet garbage collection could
> produce this exception.
> I've been using Java heavily for six years.

One problem *could* be if your TimerTask is throwing an unchecked
exception, and then you try to reschedule it, eg:

import java.util.*;

public class Test
{
public static void main (String [] args)
throws Exception
{
Timer t = new Timer ();
t.scheduleAtFixedRate (new TimerTask()
{
public void run()
{
throw new NullPointerException();
}
}, 1000, 1000);
Thread.sleep (5000);
t.scheduleAtFixedRate (new TimerTask()
{
public void run()
{
}
}, 1000, 1000);
}
}


--
Jon Skeet - <sk...@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too

Jacob Eliosoff

unread,
Oct 17, 2001, 3:43:10 PM10/17/01
to
Beautiful example. I'll bet that's it. Thanks a bunch.
-Jacob

Jon Skeet <sk...@pobox.com> wrote:
> > I'm getting this exception in a class of mine which uses a
> > java.util.Timer. The thing is I'm not canceling the Timer. There's
> > no call to cancel() anywhere in my code.

...

0 new messages