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

  • SEARCH
  • Home
  • 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 4055116
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:39:39+00:00 2026-05-20T14:39:39+00:00

I have a piece of code that looks like this: Algorithm a = null;

  • 0

I have a piece of code that looks like this:

Algorithm a = null;  
while(a == null)  
{  
    a = grid.getAlgorithm();  
}  

getAlgorithm() in my Grid class returns some subtype of Algorithm depending on what the user chooses from some options.

My problem is that even after an algorithm is selected, the loop never terminates. However, that’s not the tricky bit, if I simply place a System.out.println(“Got here”); after my call to getAlgorithm(), the program runs perfectly fine and the loop terminates as intended.

My question is: why does adding that magic print statement suddenly make the loop terminate?

Moreover, this issue first came up when I started using my new laptop, I doubt that’s related, but I figured it would be worth mentioning.

Edit: The program in question is NOT multithreaded. The code for getAlgorithm() is:

public Algorithm getAlgorithm ()  
{  
    return algorithm;  
}

Where algorithm is initially null, but will change value upon some user input.

  • 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-05-20T14:39:39+00:00Added an answer on May 20, 2026 at 2:39 pm

    You are doing active polling. This is a bad practice. You should at least let the polling thread sleep (with Thread.sleep). Since println does some io, it probably does just that. If your app is not multithreaded it is unlikely to work at all.

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

Sidebar

Related Questions

I have a piece of code that in principal looks like the below. The
I have a piece of PHP code that loops through to display all the
this is what an html structure of the webpage looks like: <body> <form> <input
I have a piece of code where I capture all exceptions and throw one
I am calling from one piece of my code through several layers of 3rd
I have a switcher that is changing backgrounds and setting a cookie using the
I am having a problem with the following query(if this is a duplicate question
I'm trying to add text labels next to my overlay images. So far the
I am using MVC 2 and entity framework 4. On my create application page

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.