mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8204243: remove Thread.destroy() and Thread.stop(Throwable)
Reviewed-by: dholmes, alanb, sspitsyn, iris
This commit is contained in:
parent
16a09483c0
commit
4ad2957dd0
6 changed files with 5 additions and 141 deletions
|
@ -937,26 +937,6 @@ class Thread implements Runnable {
|
|||
stop0(new ThreadDeath());
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws {@code UnsupportedOperationException}.
|
||||
*
|
||||
* @param obj ignored
|
||||
*
|
||||
* @deprecated This method was originally designed to force a thread to stop
|
||||
* and throw a given {@code Throwable} as an exception. It was
|
||||
* inherently unsafe (see {@link #stop()} for details), and furthermore
|
||||
* could be used to generate exceptions that the target thread was
|
||||
* not prepared to handle.
|
||||
* For more information, see
|
||||
* <a href="{@docRoot}/java.base/java/lang/doc-files/threadPrimitiveDeprecation.html">Why
|
||||
* are Thread.stop, Thread.suspend and Thread.resume Deprecated?</a>.
|
||||
* This method is subject to removal in a future version of Java SE.
|
||||
*/
|
||||
@Deprecated(since="1.2", forRemoval=true)
|
||||
public final synchronized void stop(Throwable obj) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
/**
|
||||
* Interrupts this thread.
|
||||
*
|
||||
|
@ -1061,29 +1041,6 @@ class Thread implements Runnable {
|
|||
@HotSpotIntrinsicCandidate
|
||||
private native boolean isInterrupted(boolean ClearInterrupted);
|
||||
|
||||
/**
|
||||
* Throws {@link NoSuchMethodError}.
|
||||
*
|
||||
* @deprecated This method was originally designed to destroy this
|
||||
* thread without any cleanup. Any monitors it held would have
|
||||
* remained locked. However, the method was never implemented.
|
||||
* If it were to be implemented, it would be deadlock-prone in
|
||||
* much the manner of {@link #suspend}. If the target thread held
|
||||
* a lock protecting a critical system resource when it was
|
||||
* destroyed, no thread could ever access this resource again.
|
||||
* If another thread ever attempted to lock this resource, deadlock
|
||||
* would result. Such deadlocks typically manifest themselves as
|
||||
* "frozen" processes. For more information, see
|
||||
* <a href="{@docRoot}/java.base/java/lang/doc-files/threadPrimitiveDeprecation.html">
|
||||
* Why are Thread.stop, Thread.suspend and Thread.resume Deprecated?</a>.
|
||||
* This method is subject to removal in a future version of Java SE.
|
||||
* @throws NoSuchMethodError always
|
||||
*/
|
||||
@Deprecated(since="1.5", forRemoval=true)
|
||||
public void destroy() {
|
||||
throw new NoSuchMethodError();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if this thread is alive. A thread is alive if it has
|
||||
* been started and has not yet died.
|
||||
|
|
|
@ -62,21 +62,6 @@ it succeeded. The code to ensure this would be quite complex.</li>
|
|||
</ol>
|
||||
In sum, it just isn't practical.
|
||||
<hr>
|
||||
<h3>What about <code>Thread.stop(Throwable)</code>?</h3>
|
||||
<p>In addition to all of the problems noted above, this method may
|
||||
be used to generate exceptions that its target thread is unprepared
|
||||
to handle (including checked exceptions that the thread could not
|
||||
possibly throw, were it not for this method). For example, the
|
||||
following method is behaviorally identical to Java's
|
||||
<code>throw</code> operation, but circumvents the compiler's
|
||||
attempts to guarantee that the calling method has declared all of
|
||||
the checked exceptions that it may throw:</p>
|
||||
<pre>
|
||||
static void sneakyThrow(Throwable t) {
|
||||
Thread.currentThread().stop(t);
|
||||
}
|
||||
</pre>
|
||||
<hr>
|
||||
<h3>What should I use instead of <code>Thread.stop</code>?</h3>
|
||||
<p>Most uses of <code>stop</code> should be replaced by code that
|
||||
simply modifies some variable to indicate that the target thread
|
||||
|
@ -339,13 +324,6 @@ If the <code>stop</code> method calls <code>Thread.interrupt</code>, as
|
|||
described above, it needn't call <code>notify</code> as well, but it
|
||||
still must be synchronized. This ensures that the target thread
|
||||
won't miss an interrupt due to a race condition.
|
||||
<hr>
|
||||
<h3>What about <code>Thread.destroy</code>?</h3>
|
||||
<code>Thread.destroy</code> was never implemented and has been
|
||||
deprecated. If it were implemented, it would be deadlock-prone in
|
||||
the manner of <code>Thread.suspend</code>. (In fact, it is roughly
|
||||
equivalent to <code>Thread.suspend</code> without the possibility
|
||||
of a subsequent <code>Thread.resume</code>.)
|
||||
<p><!-- Body text ends here --></p>
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue