Is there any way to force a Thread
to stop under Java 8, now that Thread.stop
has been removed? This includes forcing a thread waiting on a lock/synchronized/sleep/wait/infinite loop to stop.
This is intended as part of a watchdog for the application which can detect if it has deadlocked/frozen, force kill threads and then save the current state to avoid lost information - while there is a high chance of this information being corrupt due to forcing a thread to stop, it's better to have a copy of the possibly incorrect information than to lose it.
Attempting to save this information without stopping the locked up threads is impossible, as saving it will require acquiring locks.
Thread.stop
was removed? What great news, that was one of the most horrible, vile methods ever. In your case: Nobody can force you to acquire locks while saving the data - that will need some refactoring for you sure and it's obviously error prone, but then that's an inherent problem in what you're trying to do.Thread.stop()
has not been removed; 2. it has been deprecated for a long time, no change in Java 8 in that respect; 3. it has been used all along nevertheless, although less often. docs.oracle.com/javase/8/docs/api/java/lang/Thread.html#stop--