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 8376061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:20:08+00:00 2026-06-09T15:20:08+00:00

I tried the following and it didn’t work: Start class: public class Start implements

  • 0

I tried the following and it didn’t work:

“Start” class:

public class Start implements Runnable {

    Start start;
    LoadExample loadExample;
    Thread mainThread;
    Thread loadExampleThread;

    private boolean running = false;
    public static boolean isExampleLoaded = false;

    public static void main(String[] args) {
        begin = new Start();
        loadExample = new LoadExample();
        begin.start();
    }

    public synchronized void start() {
        mainThread = new Thread(this, "Main");
        mainThread.start();
        loadExampleThread = new Thread(loadExample, "Load Example");
        loadExampleThread.start();
    }

    public void run() {
        running = true;
        while (running) {
            if(isExampleLoaded){
                System.out.println("Loaded!");
            }
        }
    }
}

“LoadExample” class:

public class LoadExample implements Runnable {

    public void run(){
        //blabla, loading if you will...
        Start.isExampleLoaded = true;
    }
}

You might find syntax errors in the code above but that is only because I typed this without checking in Eclipse. My original code was very similar and Eclipse showed no errors or warnings.

My problem is that the code won’t print “Loaded!”.
I think this is either because (1) thread’s can’t change static variables or variables of other classes, or (2) the change is only update for the current thread and not for the other(s), but I may be wrong.

Any clarification is appreciated.

EDIT:

If you find any errors above, let me know and I will update them ASAP.

  • 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-09T15:20:10+00:00Added an answer on June 9, 2026 at 3:20 pm

    You need to mark the variable volatile in order for this example to work. Without volatile, the reading thread will read isExampleLoaded once, and not read it again, because the compiler knows that the variable has not been written to.

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

Sidebar

Related Questions

Anything I have tried didn't work. Currenly I have following code to change asp.net
I tried with following regex, but it didn't work. myString.replaceAll(\, /); Exception: java.util.regex.PatternSyntaxException: Unexpected
I tried following the instruction s but can't get the plugin to work, the
I have the following class structure: public class Fruit { } public class Apple
I tried following code to run timer in class library but timer_Elapsed wasn't fired.
I tried the following snippet in a shell script but awk didn't find $REF
My friend has an XML parsing example that I tried following, but it didn't
Tried following the instructions here: How to use Google app engine with my own
I tried following the gradle manual with their example like this but copyJars is
I tried following the answer here how to override a task making it depend

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.