Search code examples
javalimitwaitsynchronizedframe-rate

Java: wait() limits the fps to 64


I have this in my code in the main loop(2D game in a window):

try{
  synchronized(this){

    wait(3);
  }
}
catch(Exception ex) {
  System.out.println(ex);
}

This piece of code causes to FPS to cap at 64 and I don't know why. I don't use any other synchronized blocks. Amusingly, when the web browser is open, the fps is no longer capped. Could anybody tell me how to get rid of that 64 fps limit? I didn't manage to find any other topics with this problem.

EDIT:

  • Without the wait(3); - 180fps.
  • With the wait(3) and the browser(Opera) open - ~113 fps.
  • With wait(3) and without the browser - 64 fps.

How could the browser change fps?


Solution

  • Although the resolution of the parameters of wait and sleep are in milliseconds you will almost certainly never get exactly the delay you are requesting.

    On a Windows system the resolution is approximately 15ms giving 1000/15 = 66fps