A
A
Andrey Ovchinnikov2019-12-08 22:59:08
Java
Andrey Ovchinnikov, 2019-12-08 22:59:08

Why is the thread not working properly?

Good evening. There is a thread, if in a loop to output something to the console, then when the variable isStarted changes, if - is executed. If nothing is output to the console, then the if-is not executed when the variable changes. The variable changes when a response comes from the server. I don’t understand how the output to the console and the work of the stream are connected.

Thread thread = new Thread(() -> {
            for(;;){
                System.out.println("asfd");
                if (Globals.isStarted()){
                    lobby.setVisible(false);
                    game_pane.setVisible(true);
                    break;
                }
            }
            while(true){
                if (!Globals.isBlocked()){
                    getmore.setVisible(true);
                } else {
                    getmore.setVisible(false);
                }
            }
        });
        thread.start();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Ovchinnikov, 2019-12-08
@Jailpy

I understood the mistake. The isStarted method should have been made synchronized

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question