0

I wont to run my thread in background but it keeps blocking UI. In methods login() and dostaff() I use selenium webdriver to get data and display it in label, after that I refresh page and thread sleeps for 60000ms;

public static class Moderate implements Runnable {

public void run() {
    login();
    while (true) {
        dostaff();
        try {
            Thread.sleep(60000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
  }
private void login(){....};
private void dostaff(){....};
}

and I call it:

public void ModerateLoop(javafx.scene.control.Label lbl) {
    this.displayLabel = lbl;
    Moderate thread = new Moderate();
    thread.run();
}
Little Fox
  • 1,212
  • 13
  • 39

1 Answers1

3

because you are calling the method run

thread.run();

so this is blocking the invoking thread until your code in the run method is done.

you need instead to start the thread

thread.start();
ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97