Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8299419

Thread.sleep(millis) may throw OOME

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 24
    • 19, 20, 21
    • core-libs
    • None
    • b15
    • generic
    • generic

      After the addition of the JFR ThreadSleep event, the Thread.sleep(millis) method may allocate the new objects so code that uses Thread.sleep when attempting to continue after OOME may fail, e.g.

      try {
        //Try to do some heavyweight work
      }
      } catch (OutOfMemoryError e) {
      }
      // Give the GC a chance at that weakref/softred in case of slow systems
      Thread.sleep(2000);
      // then repeat

      I think it was not intentional behaviour change, can we restore the old behaviour somehow? or the code should be updated to be ready of OOM from this method?

            vklang Viktor Klang
            serb Sergey Bylokhov
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: