Files
javademos/lanes/src/ThreadStopRuntime.java
T

25 lines
1.0 KiB
Java

/**
* Thread.stop() on 25: still compiles (with a deprecation-for-removal warning) but has thrown
* UnsupportedOperationException since Java 20. It is REMOVED from the API in Java 26 (see recap26/src/broken/ThreadStopGone.java,
* docs/output/73-removed-in-26.txt). Thread.suspend() and resume() are checked the same way.
* Chapter: docs/14-lanes-21-to-25.md
*/
public class ThreadStopRuntime {
@SuppressWarnings({"removal", "deprecation"})
public static void main(String[] args) throws Exception {
System.out.println("java.version = " + System.getProperty("java.version"));
Thread t = new Thread(() -> {
try { Thread.sleep(1000); } catch (InterruptedException ignored) { }
});
t.start();
try {
t.stop();
System.out.println("Thread.stop(): accepted");
} catch (UnsupportedOperationException e) {
System.out.println("Thread.stop(): UnsupportedOperationException");
}
t.interrupt();
t.join();
}
}