views:

591

answers:

4

Basically I want a function to be called every say, 10 milliseconds.

How can I achieve that in Java?

+1  A: 

I would say you would create a thread and in the thread loop add a System.sleep(10) to make the thread "sleep" for 10 ms before continuing.

Ravi Wallau
+5  A: 

You might want to take a look at Timer.

Bombe
But beware - it calls you from a background thread.
Daniel Earwicker
It's ok, it does what I want.
hasen j
+7  A: 

Check out java.util.Timer

http://java.sun.com/javase/6/docs/api/java/util/Timer.html

jishi
A: 

You could also use a ScheduleExecutorService.

Peter Lawrey