In the code, the variable timer would specify the duration after which to end the while loop, 60 sec for example.
while(timer) { //run //terminate after 60 sec }
To stop executing java code just use this command: System. exit(1);
To set the time limit of a search, pass the number of milliseconds to SearchControls. setTimeLimit(). The following example sets the time limit to 1 second. // Set the search controls to limit the time to 1 second (1000 ms) SearchControls ctls = new SearchControls(); ctls.
Thread. sleep() method can be used to pause the execution of current thread for specified time in milliseconds.
The easiest way to delay a java program is by using Thread. sleep() method. The sleep() method is present in the Thread class. It simply pauses the current thread to sleep for a specific time.
long start = System.currentTimeMillis(); long end = start + 60*1000; // 60 seconds * 1000 ms/sec while (System.currentTimeMillis() < end) { // run }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With