javax.swing.Timer isn't running at set delay

I'm using a javax.swing.Timer instance, with the delay set to 30 milliseconds, to update the positions of some shapes within a thread-rendered image. These shapes form a contextual menu when you mouseover objects within the rendered image.

It is very apparent that the delay is not adhered to. The first couple of times you mouseover things, the delay seems as expected. After that, the delay varies from very fast to exceedingly slow.

I'm definitely stopping each spawned Timer, so there is no buildup of garbage. How is it that the Timer is able to ignore its delay?

[589 byte] By [KomodoDavea] at [2007-11-26 18:12:24]
# 1
I would suggest adding in some printlns or something to determine what is really going on.
zadoka at 2007-7-9 5:45:13 > top of Java-index,Desktop,Core GUI APIs...
# 2
Programming bug.No SSCCE, no help!!!
camickra at 2007-7-9 5:45:13 > top of Java-index,Desktop,Core GUI APIs...
# 3

> Programming bug.

I don't understand how it can be though... I mean, if you've set the delay, in what ways could it be affected?

If it's subject to the same problems any thread experiences, then I don't really see the value of having a custom class for it...

I've already put Thread.yield() calls in my animation thread, so I don't see what more I can do!

KomodoDavea at 2007-7-9 5:45:13 > top of Java-index,Desktop,Core GUI APIs...
# 4

> > Programming bug.

>

> I don't understand how it can be though... I mean, if

> you've set the delay, in what ways could it be

> affected?

There are many ways that there could be errors in your code.

> If it's subject to the same problems any thread

> experiences, then I don't really see the value of

> having a custom class for it...

>

> I've already put Thread.yield() calls in my animation

> thread, so I don't see what more I can do!

You could look at your code and try to find the problem. You could provide a SSCCE, like you have been asked. You could analyze what is happening in your program when it is running.Etc.

zadoka at 2007-7-9 5:45:13 > top of Java-index,Desktop,Core GUI APIs...
# 5

Swing Timers coalesce multiple pending ActionEvents. Whatever you're doing when the event fires is probably taking too long for a 30ms interval.

If you would just build the SSCCE, you'll probably figure it out without help from us. Though based on your recent posts, if you're setting thread priorities and what not, all bets are off.

Jasprea at 2007-7-9 5:45:13 > top of Java-index,Desktop,Core GUI APIs...
# 6

Ok, well thanks everyone for the insights. I'll try and debug it myself, thank you :)

I never post an SSCCE because I can figure it out once I know what sort of thing could go wrong in a particular situation. I just didn't know what sort of thing would affect a timer.. I'd assumed there was a guarantee of it producing the desired ActionEvent at the interval set, but I guess not.

Cheers guys.

KomodoDavea at 2007-7-9 5:45:13 > top of Java-index,Desktop,Core GUI APIs...
# 7
> I never post an SSCCE Well, then you are handicapping the people here that are trying to help you. You will get a better response when you can post one.
zadoka at 2007-7-9 5:45:13 > top of Java-index,Desktop,Core GUI APIs...
# 8

> I never post an SSCCE because...

..you are too lazy.

You've only been asked about 10 time is the past now.

If you had taken the time to whip up a short example, you probably would have noticed that it worked the way you wanted it to.

Then you would have to ask yourself the question why? What is the difference between the simple example and the more complicated example?

Thats how you solve problems, by simplifying the problem. Quit forcing us to make quesses about what your code is actually doing. If we have never seen the behaviour you are trying to describe then we are at a loss as well.

camickra at 2007-7-9 5:45:13 > top of Java-index,Desktop,Core GUI APIs...
# 9
<|:oD
KomodoDavea at 2007-7-9 5:45:13 > top of Java-index,Desktop,Core GUI APIs...