125 points · by mattiemass · 8y ago · 35 comments
Edit: FWIW, I looked through the history, and it looks like Thread.destroy() was added by Bill Joy in Aug 1995. The initial implementation was "throw new NoSuchMethodError();".
As a reminder, Thread.interrupt calls SocketChannel.close for any SocketChannel that is currently blocking.
Let's check out how SocketChannel is implemented on Android:
public synchronized int read(ByteBuffer target) ...
public synchronized void close() ...
Obviously, this causes a deadlock.The only alternative is using Thread.stop or completely creating your own SocketChannel implementation.
This was fixed in Android N in 2016, but few users have that update yet (less than a quarter)
The people who write Google’s apps _have_ to be running into this stuff. But apparently either they’re not telling the standard lib people in a timely fashion, or they are but are being ignored.
It's strange to deprecate something when you can still achieve the same effect in some roundabout way?
Isn't that true for ALL APIs? You could always rewrite any deprecated API yourself, using sun.unsafe or JNI if it was needed, or even compile your own patched SDK fork.
The main intend behind deprecation is telling people "we don't want to support this anymore and you shouldn't be using it".
This is totally orthogonal to "you won't be able to replicate this behavior".
Regardless, the deprecation serves as prominent warning that the programmer is about to shoot themselves in the foot.
(I'm actually more surprised that stop() hasn't been removed after all this time.)
Java 9 has introduced an API to get the process ID but before that, there was no defined way to get it, though it is accessible in a roundabout way via the JMX API, but even then it is not guaranteed. JNI would be another alternative.
Few languages do cancellation well. Either it doesn't work right, or it does something overly elaborate like LISP breaks.
Sounds spooky, and it does require writing code in an exception-safe way, but that’s generally easy: pure code is largely exception-safe by nature, and impure code can use “bracket” (“finally”, “mask”, “ResourceT”, &c.) to acquire & release resources—and should already be using these functions anyway to handle regular synchronous exceptions. Async exceptions are very useful for killing a task that’s using too much time/memory, or initiating a graceful shutdown.
Thats incorrect. Calling Thread#interrupted[0] clears the interrupt status and returns true if the current thread was interrupted. Thread#isInterrupted()[1] only returns the value of the interrupt status on the thread receiving the method call. The interrupt status is unaffected by that method call.
[0] https://docs.oracle.com/javase/8/docs/api/java/lang/Thread.h...
[1] https://docs.oracle.com/javase/8/docs/api/java/lang/Thread.h...