Time in Java
-
hi how are you today (SORRY FOR MY BAD ENGLISH) i have a java program , i need this program to send me every 10 seconds "hi" message but i need the program to keep running and every 10 seconds send me "hi"message how can i do it ? ty
-
hi how are you today (SORRY FOR MY BAD ENGLISH) i have a java program , i need this program to send me every 10 seconds "hi" message but i need the program to keep running and every 10 seconds send me "hi"message how can i do it ? ty
-
hi how are you today (SORRY FOR MY BAD ENGLISH) i have a java program , i need this program to send me every 10 seconds "hi" message but i need the program to keep running and every 10 seconds send me "hi"message how can i do it ? ty
Hai Williamroma you can use Thread Class to run your program continuously and use Thread.sleep(1000); method to wait for every 10 seconds. Within the if statement it exceeds 10 seconds you can display the "hi" message from your program
-
hi how are you today (SORRY FOR MY BAD ENGLISH) i have a java program , i need this program to send me every 10 seconds "hi" message but i need the program to keep running and every 10 seconds send me "hi"message how can i do it ? ty
import java.util.Timer;
public class TimerExample {
public static void main(String[] args) {
Timer timer = new Timer();
long delay = 10000; // 10 seconds
timer.schedule(new Task("object"), 0, delay);
}
}
***** Programme comme si dept soutien technique. est plein de tueurs en série et ils savent adresse de votre domicile. *****
-
Hai Williamroma you can use Thread Class to run your program continuously and use Thread.sleep(1000); method to wait for every 10 seconds. Within the if statement it exceeds 10 seconds you can display the "hi" message from your program
Just a small correction, the parameter of Thread.sleep is in milliseconds, so 1000 is 1 second while 10000 is 10 seconds it should be Thread.sleep(10000) :)