Home java Large delay (pause) in java

Large delay (pause) in java




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,

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?

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions