Over a million developers have joined DZone.

Thread Methods destroy() and stop(Throwable) Removed in JDK 11

DZone's Guide to

Thread Methods destroy() and stop(Throwable) Removed in JDK 11

Are these two Thread methods going away? Let's take a look in this post.

· Java Zone ·
Free Resource

Download Microservices for Java Developers: A hands-on introduction to frameworks and containers. Brought to you in partnership with Red Hat.

The message "RFR(s): 8204243: remove Thread.destroy() and Thread.stop(Throwable)" by @DrDeprecator (Stuart Marks) on the core-libs-dev OpenJDK mailing list is a request for review (RFR) of a changeset associated with JDK-8204243 ["remove Thread.destroy() and Thread.stop(Throwable)"]. Both the bug report and the mailing list message describe the history of these two referenced Thread methods and explain that neither method really does anything useful.

The JDK 10 Javadoc API documentation for the java.lang.Thread shows six methods on the Thread class that are deprecated. Three of which are explicitly marked for removal. The table below summarizes these deprecated Thread methods.

JDK 10
countStackFrames() 1.2 Yes Depends on deprecated suspend()
destroy() 1.5 Yes Throws NoSuchMethodError since inception
(never implemented)
resume() 1.2 No "Exists solely for use with suspend()"
stop() 1.2 No "This method is inherently unsafe."
stop(Throwable) 1.2 Yes ThrowsUnsupportedOperationException since JDK 8
suspend() 1.2 No "This method ... is inherently deadlock-prone."

It now appears that two of the three Thread methods that are deprecated and marked for removal will be removed with JDK 11. These methods include Thread.destroy() and Thread.stop(Throwable) and they should be completely removed with the release of JDK 11. The destroy()method has never done anything except throw the NoSuchMethodError.  The stop(Throwable) method hasn't done anything except throw theUnsupportedOperationException since JDK 8. Good riddance to these two fruitless methods!

Additional References

Download Building Reactive Microservices in Java: Asynchronous and Event-Based Application Design. Brought to you in partnership with Red Hat

java ,jdk 11 ,threads ,methods ,deprecation ,api

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}