< prev index next >

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

Print this page

353      * by being <em>notified</em> or <em>interrupted</em>, or until a
354      * certain amount of real time has elapsed.
355      * <p>
356      * In all respects, this method behaves as if {@code wait(timeoutMillis, 0)}
357      * had been called. See the specification of the {@link #wait(long, int)} method
358      * for details.
359      *
360      * @param  timeoutMillis the maximum time to wait, in milliseconds
361      * @throws IllegalArgumentException if {@code timeoutMillis} is negative
362      * @throws IllegalMonitorStateException if the current thread is not
363      *         the owner of the object's monitor
364      * @throws InterruptedException if any thread interrupted the current thread before or
365      *         while the current thread was waiting. The <em>interrupted status</em> of the
366      *         current thread is cleared when this exception is thrown.
367      * @see    #notify()
368      * @see    #notifyAll()
369      * @see    #wait()
370      * @see    #wait(long, int)
371      */
372     public final void wait(long timeoutMillis) throws InterruptedException {
373         long comp = Blocker.begin();






374         try {
375             wait0(timeoutMillis);
376         } catch (InterruptedException e) {
377             Thread thread = Thread.currentThread();
378             if (thread.isVirtual())
379                 thread.getAndClearInterrupt();
380             throw e;
381         } finally {
382             Blocker.end(comp);
383         }
384     }
385 
386     // final modifier so method not in vtable
387     private final native void wait0(long timeoutMillis) throws InterruptedException;
388 
389     /**
390      * Causes the current thread to wait until it is awakened, typically
391      * by being <em>notified</em> or <em>interrupted</em>, or until a
392      * certain amount of real time has elapsed.
393      * <p>
394      * The current thread must own this object's monitor lock. See the
395      * {@link #notify notify} method for a description of the ways in which
396      * a thread can become the owner of a monitor lock.
397      * <p>
398      * This method causes the current thread (referred to here as <var>T</var>) to
399      * place itself in the wait set for this object and then to relinquish any
400      * and all synchronization claims on this object. Note that only the locks
401      * on this object are relinquished; any other objects on which the current
402      * thread may be synchronized remain locked while the thread waits.
403      * <p>
404      * Thread <var>T</var> then becomes disabled for thread scheduling purposes
405      * and lies dormant until one of the following occurs:
406      * <ul>

353      * by being <em>notified</em> or <em>interrupted</em>, or until a
354      * certain amount of real time has elapsed.
355      * <p>
356      * In all respects, this method behaves as if {@code wait(timeoutMillis, 0)}
357      * had been called. See the specification of the {@link #wait(long, int)} method
358      * for details.
359      *
360      * @param  timeoutMillis the maximum time to wait, in milliseconds
361      * @throws IllegalArgumentException if {@code timeoutMillis} is negative
362      * @throws IllegalMonitorStateException if the current thread is not
363      *         the owner of the object's monitor
364      * @throws InterruptedException if any thread interrupted the current thread before or
365      *         while the current thread was waiting. The <em>interrupted status</em> of the
366      *         current thread is cleared when this exception is thrown.
367      * @see    #notify()
368      * @see    #notifyAll()
369      * @see    #wait()
370      * @see    #wait(long, int)
371      */
372     public final void wait(long timeoutMillis) throws InterruptedException {
373         if (!Thread.currentThread().isVirtual()) {
374             wait0(timeoutMillis);
375             return;
376         }
377 
378         // virtual thread waiting
379         boolean attempted = Blocker.begin();
380         try {
381             wait0(timeoutMillis);
382         } catch (InterruptedException e) {
383             // virtual thread's interrupt status needs to be cleared
384             Thread.currentThread().getAndClearInterrupt();

385             throw e;
386         } finally {
387             Blocker.end(attempted);
388         }
389     }
390 
391     // final modifier as method not in vtable
392     private final native void wait0(long timeoutMillis) throws InterruptedException;
393 
394     /**
395      * Causes the current thread to wait until it is awakened, typically
396      * by being <em>notified</em> or <em>interrupted</em>, or until a
397      * certain amount of real time has elapsed.
398      * <p>
399      * The current thread must own this object's monitor lock. See the
400      * {@link #notify notify} method for a description of the ways in which
401      * a thread can become the owner of a monitor lock.
402      * <p>
403      * This method causes the current thread (referred to here as <var>T</var>) to
404      * place itself in the wait set for this object and then to relinquish any
405      * and all synchronization claims on this object. Note that only the locks
406      * on this object are relinquished; any other objects on which the current
407      * thread may be synchronized remain locked while the thread waits.
408      * <p>
409      * Thread <var>T</var> then becomes disabled for thread scheduling purposes
410      * and lies dormant until one of the following occurs:
411      * <ul>
< prev index next >