< prev index next >

src/java.base/share/classes/java/lang/Object.java

Print this page
*** 23,11 ***
   * questions.
   */
  
  package java.lang;
  
- import jdk.internal.misc.Blocker;
  import jdk.internal.vm.annotation.IntrinsicCandidate;
  
  /**
   * Class {@code Object} is the root of the class hierarchy.
   * Every class has {@code Object} as a superclass. All objects,
--- 23,10 ---

*** 368,25 ***
       * @see    #notifyAll()
       * @see    #wait()
       * @see    #wait(long, int)
       */
      public final void wait(long timeoutMillis) throws InterruptedException {
!         if (!Thread.currentThread().isVirtual()) {
!             wait0(timeoutMillis);
-             return;
          }
  
!         // virtual thread waiting
!         boolean attempted = Blocker.begin();
!         try {
              wait0(timeoutMillis);
-         } catch (InterruptedException e) {
-             // virtual thread's interrupt status needs to be cleared
-             Thread.currentThread().getAndClearInterrupt();
-             throw e;
-         } finally {
-             Blocker.end(attempted);
          }
      }
  
      // final modifier so method not in vtable
      private final native void wait0(long timeoutMillis) throws InterruptedException;
--- 367,28 ---
       * @see    #notifyAll()
       * @see    #wait()
       * @see    #wait(long, int)
       */
      public final void wait(long timeoutMillis) throws InterruptedException {
!         if (timeoutMillis < 0) {
!             throw new IllegalArgumentException("timeout value is negative");
          }
  
!         if (Thread.currentThread() instanceof VirtualThread vthread) {
!             try {
!                 wait0(timeoutMillis);
+             } catch (InterruptedException e) {
+                 // virtual thread's interrupt status needs to be cleared
+                 vthread.getAndClearInterrupt();
+                 throw e;
+             } finally {
+                 if (timeoutMillis > 0) {
+                     vthread.cancelWaitTimeout();
+                 }
+             }
+         } else {
              wait0(timeoutMillis);
          }
      }
  
      // final modifier so method not in vtable
      private final native void wait0(long timeoutMillis) throws InterruptedException;
< prev index next >