Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Repeat the loop at a specified time

I need a loop to repeat at a specific time

For example 10 seconds :

while (Repeat every ten seconds)
        {
           // Code body
        }

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

To pause the code execution into a java loop you can use Thread.sleep(Integer) method, that will stop the execution of the thread for the specified amount of milliseconds. Here there is an official example with a for loop. In your case you could do something like this:

while (1) {
  /* your code here */
  Thread.sleep(10000);
}

The body of the while loop will be executed once every 10 seconds.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading