9:15 am - Wednesday December 19, 2018

Thread Example Program for stop(Throwable obj)

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

/**
*
*@author:candidjava.com
*@description:Thread example program for stop(Throwable obj)
*/

public class ThreadStop implements Runnable {

public void run() {
System.out.println("Starting " + Thread.currentThread().getName()
+ "....");
try {
Thread.sleep(100);
} catch (Exception e) {
}
System.out.println(Thread.currentThread().getName()
+ " has finished executing.");
}

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

th.start();
th1.start();
// stop thread th
th.stop();
System.out.println(th.getName() + " has been manually stopped.");

th.join();
th1.join();
}
}

OUTPUT:

Starting Thread-0….
Thread-0 has been manually stopped.
Starting Thread-1….
Thread-1 has finished executing.

Filed in: Z-A All Java Codes

Comments are closed.