L. Zysk
L. Zysk

Reputation: 11

Infinite loop in the background in java

I have written a java program where I need a continuous loop in the background. But with a normal while loop does not work the program.

In my program a method should be executed either all the time or every second. In this method, many conditions should be checked and a label should be updated, which indicates a time . I have already programmed this method, but I do not know how to write a loop that runs in the background so continue buttons can be pressed.

Upvotes: 0

Views: 4483

Answers (1)

Bene
Bene

Reputation: 734

Use a Thread:

Thread thread = new Thread(new Runnable() {

     public void run() {
          doSomething();
     }

});
thread.start;

Everything in the run method will be executed in another thread, so it's not blocking the ui.

Upvotes: 1

Related Questions