jdk/src/share/classes/java/lang/Object.java
author martin
Mon, 10 Mar 2008 14:32:51 -0700
changeset 48 dc5744ca15ea
parent 2 90ce3da70b43
child 1937 28c31d4a9597
permissions -rw-r--r--
4960438: (process) Need IO redirection API for subprocesses Reviewed-by: alanb, iris
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1994-2006 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.lang;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * Class <code>Object</code> is the root of the class hierarchy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * Every class has <code>Object</code> as a superclass. All objects,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * including arrays, implement the methods of this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * @author  unascribed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * @see     java.lang.Class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * @since   JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
public class Object {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    private static native void registerNatives();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
        registerNatives();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
     * Returns the runtime class of this {@code Object}. The returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     * {@code Class} object is the object that is locked by {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     * static synchronized} methods of the represented class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     * <p><b>The actual result type is {@code Class<? extends |X|>}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     * where {@code |X|} is the erasure of the static type of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     * expression on which {@code getClass} is called.</b> For
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     * example, no cast is required in this code fragment:</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * {@code Number n = 0;                             }<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * {@code Class<? extends Number> c = n.getClass(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * @return The {@code Class} object that represents the runtime
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     *         class of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * @see    <a href="http://java.sun.com/docs/books/jls/">The Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     *         Language Specification, Third Edition (15.8.2 Class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     *         Literals)</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    public final native Class<?> getClass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * Returns a hash code value for the object. This method is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * supported for the benefit of hashtables such as those provided by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * <code>java.util.Hashtable</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * The general contract of <code>hashCode</code> is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * <li>Whenever it is invoked on the same object more than once during
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     *     an execution of a Java application, the <tt>hashCode</tt> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     *     must consistently return the same integer, provided no information
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     *     used in <tt>equals</tt> comparisons on the object is modified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     *     This integer need not remain consistent from one execution of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     *     application to another execution of the same application.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * <li>If two objects are equal according to the <tt>equals(Object)</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     *     method, then calling the <code>hashCode</code> method on each of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     *     the two objects must produce the same integer result.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * <li>It is <em>not</em> required that if two objects are unequal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     *     according to the {@link java.lang.Object#equals(java.lang.Object)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     *     method, then calling the <tt>hashCode</tt> method on each of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     *     two objects must produce distinct integer results.  However, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     *     programmer should be aware that producing distinct integer results
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     *     for unequal objects may improve the performance of hashtables.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * As much as is reasonably practical, the hashCode method defined by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * class <tt>Object</tt> does return distinct integers for distinct
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * objects. (This is typically implemented by converting the internal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * address of the object into an integer, but this implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * technique is not required by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * Java<font size="-2"><sup>TM</sup></font> programming language.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * @return  a hash code value for this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * @see     java.lang.Object#equals(java.lang.Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * @see     java.util.Hashtable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    public native int hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * Indicates whether some other object is "equal to" this one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * The <code>equals</code> method implements an equivalence relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * on non-null object references:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * <li>It is <i>reflexive</i>: for any non-null reference value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     *     <code>x</code>, <code>x.equals(x)</code> should return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     *     <code>true</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * <li>It is <i>symmetric</i>: for any non-null reference values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     *     <code>x</code> and <code>y</code>, <code>x.equals(y)</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     *     should return <code>true</code> if and only if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     *     <code>y.equals(x)</code> returns <code>true</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * <li>It is <i>transitive</i>: for any non-null reference values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     *     <code>x</code>, <code>y</code>, and <code>z</code>, if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     *     <code>x.equals(y)</code> returns <code>true</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     *     <code>y.equals(z)</code> returns <code>true</code>, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     *     <code>x.equals(z)</code> should return <code>true</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * <li>It is <i>consistent</i>: for any non-null reference values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     *     <code>x</code> and <code>y</code>, multiple invocations of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     *     <tt>x.equals(y)</tt> consistently return <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     *     or consistently return <code>false</code>, provided no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     *     information used in <code>equals</code> comparisons on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     *     objects is modified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * <li>For any non-null reference value <code>x</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     *     <code>x.equals(null)</code> should return <code>false</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * The <tt>equals</tt> method for class <code>Object</code> implements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * the most discriminating possible equivalence relation on objects;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * that is, for any non-null reference values <code>x</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * <code>y</code>, this method returns <code>true</code> if and only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * if <code>x</code> and <code>y</code> refer to the same object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * (<code>x == y</code> has the value <code>true</code>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * Note that it is generally necessary to override the <tt>hashCode</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * method whenever this method is overridden, so as to maintain the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * general contract for the <tt>hashCode</tt> method, which states
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * that equal objects must have equal hash codes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * @param   obj   the reference object with which to compare.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * @return  <code>true</code> if this object is the same as the obj
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     *          argument; <code>false</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * @see     #hashCode()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * @see     java.util.Hashtable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        return (this == obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * Creates and returns a copy of this object.  The precise meaning
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * of "copy" may depend on the class of the object. The general
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * intent is that, for any object <tt>x</tt>, the expression:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * x.clone() != x</pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * will be true, and that the expression:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * x.clone().getClass() == x.getClass()</pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * will be <tt>true</tt>, but these are not absolute requirements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * While it is typically the case that:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * x.clone().equals(x)</pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * will be <tt>true</tt>, this is not an absolute requirement.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * By convention, the returned object should be obtained by calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * <tt>super.clone</tt>.  If a class and all of its superclasses (except
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * <tt>Object</tt>) obey this convention, it will be the case that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * <tt>x.clone().getClass() == x.getClass()</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * By convention, the object returned by this method should be independent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * of this object (which is being cloned).  To achieve this independence,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * it may be necessary to modify one or more fields of the object returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * by <tt>super.clone</tt> before returning it.  Typically, this means
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * copying any mutable objects that comprise the internal "deep structure"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * of the object being cloned and replacing the references to these
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * objects with references to the copies.  If a class contains only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * primitive fields or references to immutable objects, then it is usually
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * the case that no fields in the object returned by <tt>super.clone</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * need to be modified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * The method <tt>clone</tt> for class <tt>Object</tt> performs a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * specific cloning operation. First, if the class of this object does
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * not implement the interface <tt>Cloneable</tt>, then a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * <tt>CloneNotSupportedException</tt> is thrown. Note that all arrays
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * are considered to implement the interface <tt>Cloneable</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * Otherwise, this method creates a new instance of the class of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * object and initializes all its fields with exactly the contents of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * the corresponding fields of this object, as if by assignment; the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * contents of the fields are not themselves cloned. Thus, this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * performs a "shallow copy" of this object, not a "deep copy" operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * The class <tt>Object</tt> does not itself implement the interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * <tt>Cloneable</tt>, so calling the <tt>clone</tt> method on an object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * whose class is <tt>Object</tt> will result in throwing an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * exception at run time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * @return     a clone of this instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * @exception  CloneNotSupportedException  if the object's class does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     *               support the <code>Cloneable</code> interface. Subclasses
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     *               that override the <code>clone</code> method can also
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     *               throw this exception to indicate that an instance cannot
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     *               be cloned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * @see java.lang.Cloneable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    protected native Object clone() throws CloneNotSupportedException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * Returns a string representation of the object. In general, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * <code>toString</code> method returns a string that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * "textually represents" this object. The result should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * be a concise but informative representation that is easy for a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * person to read.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * It is recommended that all subclasses override this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * The <code>toString</code> method for class <code>Object</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * returns a string consisting of the name of the class of which the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * object is an instance, the at-sign character `<code>@</code>', and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * the unsigned hexadecimal representation of the hash code of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * object. In other words, this method returns a string equal to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * value of:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * getClass().getName() + '@' + Integer.toHexString(hashCode())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * </pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * @return  a string representation of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        return getClass().getName() + "@" + Integer.toHexString(hashCode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * Wakes up a single thread that is waiting on this object's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * monitor. If any threads are waiting on this object, one of them
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * is chosen to be awakened. The choice is arbitrary and occurs at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * the discretion of the implementation. A thread waits on an object's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * monitor by calling one of the <code>wait</code> methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * The awakened thread will not be able to proceed until the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * thread relinquishes the lock on this object. The awakened thread will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * compete in the usual manner with any other threads that might be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * actively competing to synchronize on this object; for example, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * awakened thread enjoys no reliable privilege or disadvantage in being
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * the next thread to lock this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * This method should only be called by a thread that is the owner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * of this object's monitor. A thread becomes the owner of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * object's monitor in one of three ways:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * <li>By executing a synchronized instance method of that object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * <li>By executing the body of a <code>synchronized</code> statement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     *     that synchronizes on the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * <li>For objects of type <code>Class,</code> by executing a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     *     synchronized static method of that class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * Only one thread at a time can own an object's monitor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * @exception  IllegalMonitorStateException  if the current thread is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     *               the owner of this object's monitor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * @see        java.lang.Object#notifyAll()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * @see        java.lang.Object#wait()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    public final native void notify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * Wakes up all threads that are waiting on this object's monitor. A
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * thread waits on an object's monitor by calling one of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * <code>wait</code> methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * The awakened threads will not be able to proceed until the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * thread relinquishes the lock on this object. The awakened threads
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * will compete in the usual manner with any other threads that might
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * be actively competing to synchronize on this object; for example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * the awakened threads enjoy no reliable privilege or disadvantage in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * being the next thread to lock this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * This method should only be called by a thread that is the owner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * of this object's monitor. See the <code>notify</code> method for a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * description of the ways in which a thread can become the owner of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * a monitor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * @exception  IllegalMonitorStateException  if the current thread is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     *               the owner of this object's monitor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * @see        java.lang.Object#notify()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * @see        java.lang.Object#wait()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    public final native void notifyAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * Causes the current thread to wait until either another thread invokes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * {@link java.lang.Object#notify()} method or the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * {@link java.lang.Object#notifyAll()} method for this object, or a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * specified amount of time has elapsed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * The current thread must own this object's monitor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * This method causes the current thread (call it <var>T</var>) to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * place itself in the wait set for this object and then to relinquish
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * any and all synchronization claims on this object. Thread <var>T</var>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * becomes disabled for thread scheduling purposes and lies dormant
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * until one of four things happens:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * <li>Some other thread invokes the <tt>notify</tt> method for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * object and thread <var>T</var> happens to be arbitrarily chosen as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * the thread to be awakened.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * <li>Some other thread invokes the <tt>notifyAll</tt> method for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * <li>Some other thread {@linkplain Thread#interrupt() interrupts}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * thread <var>T</var>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * <li>The specified amount of real time has elapsed, more or less.  If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * <tt>timeout</tt> is zero, however, then real time is not taken into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * consideration and the thread simply waits until notified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * The thread <var>T</var> is then removed from the wait set for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * object and re-enabled for thread scheduling. It then competes in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * usual manner with other threads for the right to synchronize on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * object; once it has gained control of the object, all its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * synchronization claims on the object are restored to the status quo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * ante - that is, to the situation as of the time that the <tt>wait</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * method was invoked. Thread <var>T</var> then returns from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * invocation of the <tt>wait</tt> method. Thus, on return from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * <tt>wait</tt> method, the synchronization state of the object and of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * thread <tt>T</tt> is exactly as it was when the <tt>wait</tt> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * was invoked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * A thread can also wake up without being notified, interrupted, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * timing out, a so-called <i>spurious wakeup</i>.  While this will rarely
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * occur in practice, applications must guard against it by testing for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * the condition that should have caused the thread to be awakened, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * continuing to wait if the condition is not satisfied.  In other words,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * waits should always occur in loops, like this one:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     *     synchronized (obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     *         while (&lt;condition does not hold&gt;)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     *             obj.wait(timeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     *         ... // Perform action appropriate to condition
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     *     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * (For more information on this topic, see Section 3.2.3 in Doug Lea's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * "Concurrent Programming in Java (Second Edition)" (Addison-Wesley,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * 2000), or Item 50 in Joshua Bloch's "Effective Java Programming
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * Language Guide" (Addison-Wesley, 2001).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * <p>If the current thread is {@linkplain java.lang.Thread#interrupt()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * interrupted} by any thread before or while it is waiting, then an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * <tt>InterruptedException</tt> is thrown.  This exception is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * thrown until the lock status of this object has been restored as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * described above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * Note that the <tt>wait</tt> method, as it places the current thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * into the wait set for this object, unlocks only this object; any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * other objects on which the current thread may be synchronized remain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * locked while the thread waits.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * This method should only be called by a thread that is the owner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * of this object's monitor. See the <code>notify</code> method for a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * description of the ways in which a thread can become the owner of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * a monitor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * @param      timeout   the maximum time to wait in milliseconds.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * @exception  IllegalArgumentException      if the value of timeout is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     *               negative.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * @exception  IllegalMonitorStateException  if the current thread is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     *               the owner of the object's monitor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * @exception  InterruptedException if any thread interrupted the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     *             current thread before or while the current thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     *             was waiting for a notification.  The <i>interrupted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     *             status</i> of the current thread is cleared when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     *             this exception is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * @see        java.lang.Object#notify()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * @see        java.lang.Object#notifyAll()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    public final native void wait(long timeout) throws InterruptedException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * Causes the current thread to wait until another thread invokes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * {@link java.lang.Object#notify()} method or the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * {@link java.lang.Object#notifyAll()} method for this object, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * some other thread interrupts the current thread, or a certain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * amount of real time has elapsed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * This method is similar to the <code>wait</code> method of one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * argument, but it allows finer control over the amount of time to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * wait for a notification before giving up. The amount of real time,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * measured in nanoseconds, is given by:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * 1000000*timeout+nanos</pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * In all other respects, this method does the same thing as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * method {@link #wait(long)} of one argument. In particular,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * <tt>wait(0, 0)</tt> means the same thing as <tt>wait(0)</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * The current thread must own this object's monitor. The thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * releases ownership of this monitor and waits until either of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * following two conditions has occurred:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * <li>Another thread notifies threads waiting on this object's monitor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     *     to wake up either through a call to the <code>notify</code> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     *     or the <code>notifyAll</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * <li>The timeout period, specified by <code>timeout</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     *     milliseconds plus <code>nanos</code> nanoseconds arguments, has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     *     elapsed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * The thread then waits until it can re-obtain ownership of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * monitor and resumes execution.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * As in the one argument version, interrupts and spurious wakeups are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * possible, and this method should always be used in a loop:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     *     synchronized (obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     *         while (&lt;condition does not hold&gt;)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     *             obj.wait(timeout, nanos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     *         ... // Perform action appropriate to condition
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     *     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * This method should only be called by a thread that is the owner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     * of this object's monitor. See the <code>notify</code> method for a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * description of the ways in which a thread can become the owner of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     * a monitor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * @param      timeout   the maximum time to wait in milliseconds.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * @param      nanos      additional time, in nanoseconds range
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     *                       0-999999.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * @exception  IllegalArgumentException      if the value of timeout is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     *                      negative or the value of nanos is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     *                      not in the range 0-999999.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * @exception  IllegalMonitorStateException  if the current thread is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     *               the owner of this object's monitor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * @exception  InterruptedException if any thread interrupted the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     *             current thread before or while the current thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     *             was waiting for a notification.  The <i>interrupted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     *             status</i> of the current thread is cleared when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     *             this exception is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    public final void wait(long timeout, int nanos) throws InterruptedException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        if (timeout < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            throw new IllegalArgumentException("timeout value is negative");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        if (nanos < 0 || nanos > 999999) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                                "nanosecond timeout value out of range");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        if (nanos >= 500000 || (nanos != 0 && timeout == 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            timeout++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        wait(timeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * Causes the current thread to wait until another thread invokes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * {@link java.lang.Object#notify()} method or the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * {@link java.lang.Object#notifyAll()} method for this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     * In other words, this method behaves exactly as if it simply
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * performs the call <tt>wait(0)</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * The current thread must own this object's monitor. The thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * releases ownership of this monitor and waits until another thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * notifies threads waiting on this object's monitor to wake up
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * either through a call to the <code>notify</code> method or the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * <code>notifyAll</code> method. The thread then waits until it can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     * re-obtain ownership of the monitor and resumes execution.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * As in the one argument version, interrupts and spurious wakeups are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     * possible, and this method should always be used in a loop:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     *     synchronized (obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     *         while (&lt;condition does not hold&gt;)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     *             obj.wait();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     *         ... // Perform action appropriate to condition
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     *     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * This method should only be called by a thread that is the owner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * of this object's monitor. See the <code>notify</code> method for a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * description of the ways in which a thread can become the owner of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * a monitor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * @exception  IllegalMonitorStateException  if the current thread is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     *               the owner of the object's monitor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * @exception  InterruptedException if any thread interrupted the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     *             current thread before or while the current thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     *             was waiting for a notification.  The <i>interrupted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     *             status</i> of the current thread is cleared when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     *             this exception is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     * @see        java.lang.Object#notify()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     * @see        java.lang.Object#notifyAll()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    public final void wait() throws InterruptedException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        wait(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * Called by the garbage collector on an object when garbage collection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * determines that there are no more references to the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * A subclass overrides the <code>finalize</code> method to dispose of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     * system resources or to perform other cleanup.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * The general contract of <tt>finalize</tt> is that it is invoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * if and when the Java<font size="-2"><sup>TM</sup></font> virtual
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     * machine has determined that there is no longer any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     * means by which this object can be accessed by any thread that has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     * not yet died, except as a result of an action taken by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * finalization of some other object or class which is ready to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * finalized. The <tt>finalize</tt> method may take any action, including
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * making this object available again to other threads; the usual purpose
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * of <tt>finalize</tt>, however, is to perform cleanup actions before
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * the object is irrevocably discarded. For example, the finalize method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     * for an object that represents an input/output connection might perform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     * explicit I/O transactions to break the connection before the object is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     * permanently discarded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     * The <tt>finalize</tt> method of class <tt>Object</tt> performs no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * special action; it simply returns normally. Subclasses of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * <tt>Object</tt> may override this definition.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * The Java programming language does not guarantee which thread will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * invoke the <tt>finalize</tt> method for any given object. It is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * guaranteed, however, that the thread that invokes finalize will not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * be holding any user-visible synchronization locks when finalize is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * invoked. If an uncaught exception is thrown by the finalize method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * the exception is ignored and finalization of that object terminates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * After the <tt>finalize</tt> method has been invoked for an object, no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * further action is taken until the Java virtual machine has again
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     * determined that there is no longer any means by which this object can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * be accessed by any thread that has not yet died, including possible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * actions by other objects or classes which are ready to be finalized,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     * at which point the object may be discarded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     * The <tt>finalize</tt> method is never invoked more than once by a Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     * virtual machine for any given object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     * Any exception thrown by the <code>finalize</code> method causes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     * the finalization of this object to be halted, but is otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     * ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     * @throws Throwable the <code>Exception</code> raised by this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    protected void finalize() throws Throwable { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
}