< prev index next >

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

Print this page




 330      * Causes the current thread to wait until it is awakened, typically
 331      * by being <em>notified</em> or <em>interrupted</em>, or until a
 332      * certain amount of real time has elapsed.
 333      * <p>
 334      * In all respects, this method behaves as if {@code wait(timeoutMillis, 0)}
 335      * had been called. See the specification of the {@link #wait(long, int)} method
 336      * for details.
 337      *
 338      * @param  timeoutMillis the maximum time to wait, in milliseconds
 339      * @throws IllegalArgumentException if {@code timeoutMillis} is negative
 340      * @throws IllegalMonitorStateException if the current thread is not
 341      *         the owner of the object's monitor
 342      * @throws InterruptedException if any thread interrupted the current thread before or
 343      *         while the current thread was waiting. The <em>interrupted status</em> of the
 344      *         current thread is cleared when this exception is thrown.
 345      * @see    #notify()
 346      * @see    #notifyAll()
 347      * @see    #wait()
 348      * @see    #wait(long, int)
 349      */
 350     public final native void wait(long timeoutMillis) throws InterruptedException;













 351 
 352     /**
 353      * Causes the current thread to wait until it is awakened, typically
 354      * by being <em>notified</em> or <em>interrupted</em>, or until a
 355      * certain amount of real time has elapsed.
 356      * <p>
 357      * The current thread must own this object's monitor lock. See the
 358      * {@link #notify notify} method for a description of the ways in which
 359      * a thread can become the owner of a monitor lock.
 360      * <p>
 361      * This method causes the current thread (referred to here as <var>T</var>) to
 362      * place itself in the wait set for this object and then to relinquish any
 363      * and all synchronization claims on this object. Note that only the locks
 364      * on this object are relinquished; any other objects on which the current
 365      * thread may be synchronized remain locked while the thread waits.
 366      * <p>
 367      * Thread <var>T</var> then becomes disabled for thread scheduling purposes
 368      * and lies dormant until one of the following occurs:
 369      * <ul>
 370      * <li>Some other thread invokes the {@code notify} method for this




 330      * Causes the current thread to wait until it is awakened, typically
 331      * by being <em>notified</em> or <em>interrupted</em>, or until a
 332      * certain amount of real time has elapsed.
 333      * <p>
 334      * In all respects, this method behaves as if {@code wait(timeoutMillis, 0)}
 335      * had been called. See the specification of the {@link #wait(long, int)} method
 336      * for details.
 337      *
 338      * @param  timeoutMillis the maximum time to wait, in milliseconds
 339      * @throws IllegalArgumentException if {@code timeoutMillis} is negative
 340      * @throws IllegalMonitorStateException if the current thread is not
 341      *         the owner of the object's monitor
 342      * @throws InterruptedException if any thread interrupted the current thread before or
 343      *         while the current thread was waiting. The <em>interrupted status</em> of the
 344      *         current thread is cleared when this exception is thrown.
 345      * @see    #notify()
 346      * @see    #notifyAll()
 347      * @see    #wait()
 348      * @see    #wait(long, int)
 349      */
 350     public final void wait(long timeoutMillis) throws InterruptedException {
 351         try {
 352             wait0(timeoutMillis);
 353         } catch (InterruptedException e) {
 354             Fiber<?> fiber = Fiber.currentFiber();
 355             if (fiber != null) {
 356                 fiber.isInterrupted(true);
 357             }
 358             throw e;
 359         }
 360     }
 361 
 362     // final modifier so method not in vtable
 363     private final native void wait0(long timeoutMillis) throws InterruptedException;
 364 
 365     /**
 366      * Causes the current thread to wait until it is awakened, typically
 367      * by being <em>notified</em> or <em>interrupted</em>, or until a
 368      * certain amount of real time has elapsed.
 369      * <p>
 370      * The current thread must own this object's monitor lock. See the
 371      * {@link #notify notify} method for a description of the ways in which
 372      * a thread can become the owner of a monitor lock.
 373      * <p>
 374      * This method causes the current thread (referred to here as <var>T</var>) to
 375      * place itself in the wait set for this object and then to relinquish any
 376      * and all synchronization claims on this object. Note that only the locks
 377      * on this object are relinquished; any other objects on which the current
 378      * thread may be synchronized remain locked while the thread waits.
 379      * <p>
 380      * Thread <var>T</var> then becomes disabled for thread scheduling purposes
 381      * and lies dormant until one of the following occurs:
 382      * <ul>
 383      * <li>Some other thread invokes the {@code notify} method for this


< prev index next >