Bets way to setting an interval?

Hi

I was wondering what is the best way to set an interval in Java.

For example if you want to move objects or do some actions in a particular time. I want to create something that will give me the option to check stuff and do stuff like every x milliseconds. What is the best way to do this, guaranteeing that the if the program is slowed down the timing mechanism will work as planned (so needs to have priority) and that the whole process uses the least possible CPU power.

Thanks very much for any ideas!

ponggr

[546 byte] By [ponggra] at [2007-11-27 5:37:21]
# 1
Do you want to be more specific? stuff = a lot of things. On your request I could say use a java.util.Timer object with foo (not bar) and that should do the trick.See here: http://www.onjava.com/pub/a/onjava/2004/03/10/quartz.htmlMessage was edited by: _helloWorld_
_helloWorld_a at 2007-7-12 15:09:21 > top of Java-index,Java Essentials,Java Programming...
# 2

Thanks for your reply.

The "stuff" I refer to is mostly moving graphics and playing sounds.

i dont care about time but intervals since I can have a counter that will count how many times the interval was run. So I think I need something really simple but really efficient since it will run all the time.

ponggra at 2007-7-12 15:09:21 > top of Java-index,Java Essentials,Java Programming...
# 3
If you want to do something in a Swing application at regular intervals then use a javax.swing.Timer object to do that. And if you have a computer that's less than 20 years old then forget about obsessing about efficiency and just write code.
DrClapa at 2007-7-12 15:09:21 > top of Java-index,Java Essentials,Java Programming...