3 ms·
It's strange to deprecate something when you still can get exactly the same behavior by grabbing the thread's PID and then shelling out with a `kill -9`.
by derefr 9y ago
It's strange to deprecate something when you still can get exactly the same behavior by grabbing the thread's PID and then shelling out with a `kill -9`.
- lomnakkus 9y agoHow do you get a thread's PID in Java/on the JVM? 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.)
- derefr 9y agoOn a Java Card or other JVM-unikernel device, Thread.stop() would be the only way for a system watchdog process (e.g. an OOM killer) to be implemented.
- smarks 9y agoThere are narrow and unsafe uses of the no-arg Thread.stop() overload so it remains in the platform, although deprecated. There is an overload Thread.stop(Throwable) that is deprecated “for removal”. It’s been a no-op for several releases and the API will eventually be removed entirely.
- kitd 9y agoThread ID != process ID. 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.
- coldtea 9y agoThis argument doesn't make any sense. 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".