Example & Tutorial understanding programming in easy ways.

How to stop thread in Java?

Java provides rich APIs for everything but ironically Java doesn't
provide a sure shot way of stopping thread.

There was some control methods in JDK
1.0 e.g. stop(), suspend() and resume() which was deprecated in later releases
due to potential deadlock threats, from then Java API designers has not made any
effort to provide a consistent, thread-safe and elegant way to stop threads.

Programmers mainly rely on the fact that thread stops automatically as soon as they
finish execution of run() or call() method. To manually stop, programmers either
take advantage of volatile boolean variable and check in every iteration if run method
has loops or interrupt threads to abruptly cancel tasks.

Read More →
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!