I make Java applications. It became necessary, under certain conditions, to pause program execution for a long time (an hour or even more). The code is executed in a separate thread.
How correctly will it be used for such a long pause
Thread.sleep(*очень большое число*)
Maybe there is another, more correct way?
InterruptedException
may occur. Maybe it's better to use something likeTimer
,TimerTask
? - Vladyslav Matviienkotimer
starts a separate thread after some time, but does not pause the program. To pause the main thread will come up with a way to synchronize it with the timer. It will be harder tosleep
- Sergeygoto
is not a mortal sin. In addition, in the secondary thread - usesleep
as much as fit. But if you want to use it in the main thing - this is wrong, disgusting and terrible by definition. - Vladyslav Matviienko