javamultithreadingthread-sleep

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


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


Solution

  • 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);
    }