How can we make a thread to sleep for a infinite time in java?

Logesh picture Logesh · Jun 15, 2015 · Viewed 14.8k times · Source

Pls help me to understand how can we make a thread to sleep for a infinite time period .

Answer

user1121883 picture user1121883 · Jun 15, 2015

I can't think of a good reason for doing this. As one of the comments noted Long.MAX_VALUE is roughly 292 billion years so probably Thread.sleep(Long.MAX_VALUE) is enough. But if you want a theoretical infinite sleep solution:

while (true) {
    Thread.sleep(Long.MAX_VALUE);
}