run x times a second

How do i make a loop only run x times a second. There is something with getting current time and dividing, and stuff with something and sleeping for that time. Kinda like max FPS, i have no idea how to dsecribe it, i've seen it done a thousand times before but i cant google something i dont know what its called.

Sorry if htis makes no sense, but its really really simple, i jsut dont know how.

thanks

[422 byte] By [fubza] at [2007-10-2 9:17:50]
# 1

Thread t = new Thread();

int amountPerSecond = 10;

try {

for (int i = 0; i < amountPerSecond; i++) {

System.out.println("test");

t.sleep(1000 / amountPerSecond);

}

} catch (InterruptedException e) {}

This'll make it loop amountPerSecond times per second.

destina at 2007-7-16 23:24:56 > top of Java-index,Java Essentials,Java Programming...
# 2
THANK YOU SOOOOOOOOOOOOOOOOO MUCH!!!!!!*HUG*sorry... ^_^
fubza at 2007-7-16 23:24:56 > top of Java-index,Java Essentials,Java Programming...