📄 javalang.doc1.html
字号:
<pre><a name="28499"></a>super.clone()
</pre><a name="33394"></a>
<p><font size=+1><strong>20.1.6 </strong> <code>public final void <code><b>wait</b></code>()<br>throws IllegalMonitorStateException,      InterruptedException</code></font>
<p>
<a name="33395"></a>
This method causes the current thread to wait until some other thread invokes the
<code>notify</code> method <a href="javalang.doc1.html#13789">(§20.1.9)</a> or the <code>notifyAll</code> method <a href="javalang.doc1.html#13790">(§20.1.10)</a> for this object.
<p><a name="28160"></a>
In other words, this method behaves exactly as if it simply performs the call <code>wait(0)</code> <a href="javalang.doc1.html#14926">(§20.1.7)</a>.<p>
<a name="14926"></a>
<p><font size=+1><strong>20.1.7 </strong> <code>public final void <code><b>wait</b></code>(long millis)<br> throws IllegalMonitorStateException,      InterruptedException</code></font>
<p>
<a name="28260"></a>
This method causes the current thread to wait until either some other thread
invokes the <code>notify</code> method <a href="javalang.doc1.html#13789">(§20.1.9)</a> or the <code>notifyAll</code> method <a href="javalang.doc1.html#13790">(§20.1.10)</a> for
this object, or a certain amount of real time has elapsed.
<p><a name="28267"></a>
This method may be called only when the current thread is already synchronized on this object. If the current thread does not own the lock on this object, an <code>IllegalMonitorStateException</code> is thrown.<p>
<a name="28211"></a>
This method causes the current thread (call it <i>T</i>) to place itself in the wait set <a href="17.doc.html#28471">(§17.14)</a> for this object and then to relinquish any and all synchronization claims on this object. Thread <i>T</i> becomes disabled for thread scheduling purposes and lies dormant until one of four things happens:<p>
<ul><a name="28119"></a>
<li>Some other thread invokes the <code>notify</code> method for this object and thread <i>T</i> happens to be arbitrarily chosen as the thread to be awakened.
<a name="28120"></a>
<li>Some other thread invokes the <code>notifyAll</code> method for this object.
<a name="29107"></a>
<li>Some other thread interrupts <a href="javalang.doc18.html#29179">(§20.20.31)</a> thread <i>T</i>.
<a name="28130"></a>
<li>The specified amount of real time has elapsed, more or less. The amount of real time, measured in milliseconds, is given by <code>millis</code>. If <code>millis</code> is zero, however, then real time is not taken into consideration and the thread simply waits until notified.
</ul><a name="28148"></a>
The thread <i>T</i> is then removed from the wait set for this object and re-enabled for
thread scheduling. It then competes in the usual manner with other threads for the
right to synchronize on the object; once it has gained control of the object, all its
synchronization claims on the object are restored to the status quo ante-that is, to
the situation as of the time that the <code>wait</code> method was invoked. Thread <i>T</i> then
returns from the invocation of the <code>wait</code> method. Thus, on return from the <code>wait</code>
method, the synchronization state of the object and of thread <i>T</i> is exactly as it was
when the <code>wait</code> method was invoked.
<p><a name="29110"></a>
If the current thread is interrupted <a href="javalang.doc18.html#29179">(§20.20.31)</a> by another thread while it is waiting, then an <code>InterruptedException</code> is thrown. This exception is not thrown until the lock status of this object has been restored as described above.<p>
<a name="28155"></a>
Note that the <code>wait</code> method, as it places the current thread into the wait set for this object, unlocks only this object; any other objects on which the current thread may be synchronized remain locked while the thread waits.<p>
<a name="32520"></a>
<p><font size=+1><strong>20.1.8 </strong> <code>public final void <code><b>wait</b></code>(long millis, int nanos)<br> throws IllegalMonitorStateException,      InterruptedException</code></font>
<p>
<a name="32521"></a>
This method causes the current thread to wait until either some other thread
invokes the <code>notify</code> method <a href="javalang.doc1.html#13789">(§20.1.9)</a> or the <code>notifyAll</code> method <a href="javalang.doc1.html#13790">(§20.1.10)</a> for
this object, or some other thread interrupts the current thread, or a certain amount
of real time has elapsed.
<p><a name="28106"></a>
The amount of real time, measured in nanoseconds, is given by:<p>
<pre><a name="28107"></a><code>1000000*millis+nanos
</code></pre><a name="28178"></a>
In all other respects, this method does the same thing as the method <code>wait</code> of one
argument <a href="javalang.doc1.html#14926">(§20.1.7)</a>. In particular, <code>wait(0,</code> <code>0)</code> means the same thing as <code>wait(0)</code>.
<p><a name="13789"></a>
<p><font size=+1><strong>20.1.9 </strong> <code>public final void <code><b>notify</b></code>()<br>throws IllegalMonitorStateException</code></font>
<p>
<a name="27974"></a>
If any threads are waiting <a href="javalang.doc1.html#14926">(§20.1.7)</a> on this object, one of them is chosen to be
awakened. The choice is arbitrary and at the discretion of the implementation.
<p><a name="28277"></a>
The <code>notify</code> method may be called only when the current thread is already synchronized on this object. If the current thread does not own the lock on this object, an <code>IllegalMonitorStateException</code> is thrown.<p>
<a name="28289"></a>
The awakened thread will not be able to proceed until the current thread relinquishes the lock on this object. The awakened thread will compete in the usual manner with any other threads that might be actively competing to synchronize on this object; for example, the awakened thread enjoys no reliable privilege or disadvantage in being the next thread to lock this object.<p>
<a name="13790"></a>
<p><font size=+1><strong>20.1.10 </strong> <code>public final void <code><b>notifyAll</b></code>()<br>throws IllegalMonitorStateException</code></font>
<p>
<a name="28304"></a>
All the threads waiting <a href="javalang.doc1.html#14926">(§20.1.7)</a> on this object are awakened.
<p><a name="28317"></a>
The <code>notifyAll</code> method may be called only when the current thread is already synchronized on this object. If the current thread does not own the lock on this object, an <code>IllegalMonitorStateException</code> is thrown.<p>
<a name="28306"></a>
The awakened threads will not be able to proceed until the current thread relinquishes the lock on this object. The awakened threads will compete in the usual manner with any other threads that might be actively competing to synchronize on this object; for example, the awakened threads enjoy no reliable privilege or disadvantage in being the next thread to lock this object.<p>
<a name="23198"></a>
<p><font size=+1><strong>20.1.11 </strong> <code>protected void <code><b>finalize</b></code>() throws Throwable</code></font>
<p>
<a name="28342"></a>
The general contract of <code>finalize</code> is that it is invoked if and when the Java Virtual
Machine has determined that there is no longer any means by which this object
can be accessed by any thread that has not yet died <a href="12.doc.html#48744">(§12.7)</a>, except as a result of an
action taken by the finalization of some other object or class which is ready to be
finalized. The <code>finalize</code> method may take any action, including making this
object available again to other threads; the usual purpose of <code>finalize</code>, however,
is to perform cleanup actions before the object is irrevocably discarded. For example,
the <code>finalize</code> method for an object that represents an input/output connection
might perform explicit I/O transactions to break the connection before the object
is permanently discarded.
<p><a name="28363"></a>
The <code>finalize</code> method of class <code>Object</code> performs no special action; it simply returns normally. Subclasses of <code>Object</code> may override this definition.<p>
<a name="28343"></a>
Java does not guarantee which thread will invoke the <code>finalize</code> method for any given object. It is guaranteed, however, that the thread that invokes <code>finalize</code> will not be holding any user-visible synchronization locks when <code>finalize</code> is invoked. If an uncaught exception is thrown by the <code>finalize</code> method, the exception is ignored and finalization of that object terminates.<p>
<a name="28344"></a>
After the <code>finalize</code> method has been invoked for an object, no further action is taken until the Java Virtual Machine has again determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, including possible actions by other objects or classes which are ready to be finalized, at which point the object may be discarded.<p>
<a name="32361"></a>
The <code>finalize</code> method is never invoked more than once by a Java Virtual Machine for any given object.<p>
<a name="31348"></a>
<h1>20.2 The Interface <code>java.lang.Cloneable</code></h1>
<a name="31349"></a>
The <code>Cloneable</code> interface should be implemented by any class that is intended to
support or override the method <code>clone</code> <a href="javalang.doc1.html#14934">(§20.1.5)</a>.
<p><pre><a name="31350"></a>public interface <code><b>Cloneable</b></code> { }
<a name="31383"></a>
</pre><a name="34773"></a>
The interface <code>Cloneable</code> declares no methods.<img src="javalang.doc.anc47.gif">
<p>
<hr>
<!-- This inserts footnotes--><p>
<a href="index.html">Contents</a> | <a href="javalang.doc.html">Prev</a> | <a href="javalang.doc2.html">Next</a> | <a href="j.index.doc1.html">Index</a>
<p>
<font size=-1>Java Language Specification (HTML generated by Suzette Pelouch on February 24, 1998)<br>
<i><a href="jcopyright.doc.html">Copyright © 1996 Sun Microsystems, Inc.</a>
All rights reserved</i>
<br>
Please send any comments or corrections to <a href="mailto:doug.kramer@sun.com">doug.kramer@sun.com</a>
</font>
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -