< prev index next >

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

Print this page

  8  * particular file as subject to the "Classpath" exception as provided
  9  * by Oracle in the LICENSE file that accompanied this code.
 10  *
 11  * This code is distributed in the hope that it will be useful, but WITHOUT
 12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14  * version 2 for more details (a copy is included in the LICENSE file that
 15  * accompanied this code).
 16  *
 17  * You should have received a copy of the GNU General Public License version
 18  * 2 along with this work; if not, write to the Free Software Foundation,
 19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20  *
 21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 22  * or visit www.oracle.com if you need additional information or have any
 23  * questions.
 24  */
 25 
 26 package java.lang;
 27 

 28 import jdk.internal.vm.annotation.IntrinsicCandidate;
 29 
 30 /**
 31  * Class {@code Object} is the root of the class hierarchy.
 32  * Every class has {@code Object} as a superclass. All objects,
 33  * including arrays, implement the methods of this class.
 34  *
 35  * @see     java.lang.Class
 36  * @since   1.0
 37  */
 38 public class Object {
 39 
 40     /**
 41      * Constructs a new object.
 42      */
 43     @IntrinsicCandidate
 44     public Object() {}
 45 
 46     /**
 47      * Returns the runtime class of this {@code Object}. The returned

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
















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

  8  * particular file as subject to the "Classpath" exception as provided
  9  * by Oracle in the LICENSE file that accompanied this code.
 10  *
 11  * This code is distributed in the hope that it will be useful, but WITHOUT
 12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14  * version 2 for more details (a copy is included in the LICENSE file that
 15  * accompanied this code).
 16  *
 17  * You should have received a copy of the GNU General Public License version
 18  * 2 along with this work; if not, write to the Free Software Foundation,
 19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20  *
 21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 22  * or visit www.oracle.com if you need additional information or have any
 23  * questions.
 24  */
 25 
 26 package java.lang;
 27 
 28 import jdk.internal.misc.Blocker;
 29 import jdk.internal.vm.annotation.IntrinsicCandidate;
 30 
 31 /**
 32  * Class {@code Object} is the root of the class hierarchy.
 33  * Every class has {@code Object} as a superclass. All objects,
 34  * including arrays, implement the methods of this class.
 35  *
 36  * @see     java.lang.Class
 37  * @since   1.0
 38  */
 39 public class Object {
 40 
 41     /**
 42      * Constructs a new object.
 43      */
 44     @IntrinsicCandidate
 45     public Object() {}
 46 
 47     /**
 48      * Returns the runtime class of this {@code Object}. The returned

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