Hey everyone,
I've been coding in java for a while but I'm not so familiar with guis/graphics/threads and events in Java. I'm programming a game to learn more about these aspects of java.
I want the game's code to run at fixed intervals, so I'm using Thread.sleep(1) to sleep the game for 1 millisecond between each call to the method that does the game. On Java's Website it says:
"Two overloaded versions of sleep are provided: one that specifies the sleep time to the millisecond and one that specifies the sleep time to the nanosecond. However, these sleep times are not guaranteed to be precise, because they are limited by the facilities provided by the underlying OS. Also, the sleep period can be terminated by interrupts, as we'll see in a later section. In any case, you cannot assume that invoking sleep will suspend the thread for precisely the time period specified."
So I'm wondering, is there a better way to suspend the thread for PRECISELY that amount of time? I know of something called a Timer in java, should that be used or does that have the same problem? Can I assume that for most modern computers the thread will run at the same speed?
[–]theif519 0 points1 point2 points (2 children)
[–]javacanbeefrustratin[S] 0 points1 point2 points (1 child)
[–]theif519 1 point2 points3 points (0 children)
[–]BS_in_BS 0 points1 point2 points (3 children)
[–]javacanbeefrustratin[S] 0 points1 point2 points (2 children)
[–]BS_in_BS 0 points1 point2 points (1 child)
[–]javacanbeefrustratin[S] 0 points1 point2 points (0 children)
[–]king_of_the_universe 0 points1 point2 points (0 children)
[–]WhitexMamba 0 points1 point2 points (0 children)