Thread.sleep(millis) may throw OOME

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: P4
    • 24
    • Affects Version/s: 19, 20, 21
    • Component/s: 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?

            Assignee:
            Viktor Klang
            Reporter:
            Sergey Bylokhov
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: