1 Reply Latest reply on Apr 20, 2010 9:13 AM by gimbal2

    Thread not coming out of sleep !!!

    807580
      I have the following code that takes my main thread into sleep mode.
       while (!StopFile.exists()) {
                process();
                log.info("Process ended Successfully");
                int sleepTimeInInt = (Integer.parseInt(sleeptime)) * 60 * 1000;
                try {
                    log.warn("Program Sleeping for " + sleeptime + " min. ");
                    Thread.sleep(sleepTimeInInt);
                    log.warn("Program Awake.");
                } catch (Exception exe) {
                    log.error("Caught Exeption in interrupting Thread" + exe.getMessage());
                    EmailUtil.logException(exe, log);
                }
      
      }
      The sleep time (sleeptime) is taken from a property files and it is configured as 10 minutes.
      This works fine and I get the following logs generated for the above code:
      - Program Sleeping for 10 min.
      - Program Awake.
      i.e. the program sleeps for 10 minutes everytime and is awake as soon as it comes out of sleep

      But the latest log says that the thread is in sleep i.e. it is awake.It did not log
      - Program Awake
      This issue is identified rarely and I am not able to find out why doesn't the thread comes out of sleep
      Please help.
        • 1. Re: Thread not coming out of sleep !!!
          gimbal2
          If you want to catch all possible exceptions, do a catch(Throwable), not catch(Exception).

          Other than that I cannot say why this behavior is occurring from the code you posted. You do always get the log line before the sleep call (in other words, is the thread even put to sleep)?

          Perhaps you will want to switch to a Timer structure in stead. Turn the thread into a timer task and schedule it to invoke once after 'sleepTimeInInt' milliseconds.