Share on Google+Share on Google+

Java Thread : stop() method

In this section we are going to describe stop() method with example in java thread.

Java Thread : stop() method

In this section we are going to describe stop() method with example in java thread.

stop() method :

Java thread provides method stop to stop any running thread. It is deprecated  as it causes exceptions. The main problem of using stop() method is that it cause damaged state of object as when you call Thread.stop() method, it may suddenly stop the execution of thread.

public final void stop() - This method forces the thread to stop execution of running thread.
It throws SecurityException if the current thread cannot modify the thread.

Example :

public class ThreadStop implements Runnable {

	public void run() {
		System.out.println("Starting " + Thread.currentThread().getName()
				+ "....");
		try {
		} catch (Exception e) {
				+ " execution completed.");

	public static void main(String[] args) throws Exception {
		Thread thread1 = new Thread(new ThreadStop());
		Thread thread2 = new Thread(new ThreadStop());

		// stop thread thread1
		System.out.println(thread1.getName() + " stopped by user.");


Output :

Thread-0 stopped by user.
Starting Thread-1....
Thread-1 execution completed.


Posted on: October 20, 2012 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.


Advertisement null