Making Java applications. There was a need when performing certain conditions to make a pause of the program for a long time (hour or even more).
The code is performed separately.
How much will it be right for such a big pause
thread.sleep (* Very large number *)
maybe there is another, more correct way?
Answer 1, Authority 100%
It will be more correct to use the timer or Scheduledexecutor (OM) for example, like this:
Timer T = New Timer ();
T.ScheduleatFixedrate (New Timertask () {
Public void Run () {
System.out.PrintLN ("Do Task");
}
}, 0, 100);
scheduledexecutorservice service = executors.newsinglethreadscheduledexecutor ();
service.schedulewithfixeddelay (
() - & gt; {System.out.printLN ("Do Task"); },
0, 1,
Timeunit.hours);
Answer 2
try {
Thread.sleep (1000 * 60 * 60);
} Catch (InterruptedException EX) {}
Answer 3
timeunit.seconds.sleep (1);
Timeunit.minutes.sleep (1);
Timeunit.hours.sleep (1);
Timeunit.days.sleep (1);
does not suit this?