Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9153955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:21:21+00:00 2026-06-17T12:21:21+00:00

I have experienced weird behaviour while coding a simple game. Basically, I create a

  • 0

I have experienced weird behaviour while coding a simple game. Basically, I create a thread with an infinite loop that fires an event in my game every couple of seconds. With the Sysout(runAnimation) in place everything works fine. However as soon as I remove it the even stops occurring.

It appears that the system.out calll is affecting the behavior of the program, does anyone have an idea why this could be happening

Here is the loop:

private void run(){
            long lastTime = -1;
            while(true){
                int timePerStep = (int) Math.ceil(ANIM_TIME/frequency);
                System.out.println(runAnimation);
                if(runAnimation && System.currentTimeMillis() - lastTime > timePerStep){
                    lastTime = System.currentTimeMillis();
                    controller.step();
                    try {
                        Thread.sleep(timePerStep);
                    } catch (InterruptedException e) {
                        Thread.currentThread().interrupt();
                    }
                }
            }
    }

It’s started during the construction of my class as follows:

animThread = new Thread(new Runnable() {
            @Override
            public void run() {
                GUIView.this.run();
            }
        });
animThread.start();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T12:21:22+00:00Added an answer on June 17, 2026 at 12:21 pm

    The System.out.println() call is synchronized (most PrintWriter method calls are) so I suspect that there is something that you are not synchronizing on inside of your code. I wonder about the runAnimation field. Could it be that it is set in another thread? Maybe it needs to be volatile? Any field that is modified in one thread and read in another needs to be synchronized or volatile. Reading the Java thread tutorial around synchronization may help.

    Without seeing more of the code, it’s hard to put a finger on it but I suspect this answer will help anyway.

    Lastly, do you really want your thread to spin until runAnimation is true? That’s a very bad practice. Maybe you should sleep for some time in the loop if runAnimation is false as well. Another idea is to use a CountDownLatch or other signaling mechanism to pause your thread until it needs to do the animation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Today I experienced a weird problem while trying to remotely debug an application built
Have you ever experienced that the Bootstrap doesn't save (with flush or without flush
I have experienced a weird problem with javascript. The problem page uses some jQuery
I have a cron job that isn't running. I'm not terribly experienced in this
I have a weird problem with a simple NSScrollView on the Mac. I just
we have just experienced a weird error on our applications connecting to a clustered
I have a rather small but weird problem that I can't seem to fix.
I have a really weird issue that I can't figure out with comparing objects
We have a mid-size SQL Server based application that has no indexes defined. Not
I have experienced AlphaBeta algorithm with my own old chess engine and now i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.