class ThDemo extends Thread { public void run() { int x; for(x=1;x<=10;x++) { try { Thread.sleep(2000); System.out.println(x); } catch(Exception e) { System.out.println(e); } } } } public class Main { public static void main(String args[]) { ThDemo d1=new ThDemo(); ThDemo d2=new ThDemo(); ThDemo d3=new ThDemo(); d1.start(); d2.start(); d3.stop(); System.out.println("Thread d3 is stopped"); } }
1
1
2
2
3
3
4
4
5
5
6
6
7
7
8
8
9
9
10
10
Thread d3 is stopped