Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Is this even a valid way of getting Ticks Per Second?

  1. #1
    Join Date
    Jan 2013
    My Mood
    Thanked 4 Times in 4 Posts

    Default Is this even a valid way of getting Ticks Per Second?

    Hello all. I've been recently working a bunch on my game, and I've seen a lot of simple game examples calculate Ticks/Frames per seconds in some odd way that uses a lot of variables. And I have a small piece of code in my game that calculates how many ticks passed every second. It seems really easy and I was wondering why no-one else used the method. Here is mine:

    int ticks = 0;
    Thread tickThread = new Thread(new Runnable(){
      public void run(){
          }catch(Exception e){}
          //Then show user ticks that have
    public Renderer(){
    //... inside update method
    public void update(){

    It pretty much uses a thread sleeping for 1000 milliseconds, then shows the user the amount of ticks that have passed. update() is called every game loop.
    So, is there an easier way? I've never seen anyone use this method. In LWJGL it is very accurate.

  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Washington, DC
    My Mood
    Thanked 704 Times in 595 Posts

    Default Re: Is this even a valid way of getting Ticks Per Second?

    I'm not sure how you'd use this code, as it seems incomplete. For example, I don't see any reset of the ticks value. I'd suggest putting together an SSCCE that demonstrates exactly how it would be used, if you really want useful replies.

    But by introducing threading, you're introducing uncertainty into your fps count. For example, it's theoretically possible for this thread to return from the Thread.sleep() call, but not actually get control until much later. That probably won't happen, but you will see some wiggle in your data because of that problem.
    How to Ask Questions the Smart Way
    Static Void Games - GameDev tutorials, free Java and JavaScript hosting!
    Static Void Games forum - Come say hello!

Similar Threads

  1. Valid Java, compile
    By AnilS23 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 13th, 2012, 09:51
  2. Valid user input
    By ChristopherLowe in forum Java Programming Tutorials
    Replies: 1
    Last Post: June 21st, 2011, 16:53
  3. Help on a HW assignment if password is valid or invalid?
    By DeadlySwordz in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 10th, 2011, 08:48
  4. Valid toString method?
    By dcshoecousa in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 4th, 2010, 11:55