Write a Thread stop() program

Write a Thread stop() program

Program
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");    
    }
}


Output:

1
1
2
2
3
3
4
4
5
5
6
6
7
7
8
8
9
9
10
10
Thread d3 is stopped


Multi Threading In Java



More Questions


230 . How to reverse the words from the given string sentence?
231 . How to swap two strings without using the third variable?
232 . Write a java program to display message a 2sec time gap without using Multi Threading
233 . Write a java program to display message a 2sec time gap using Thread class
234 . Write a java program to display message a 2sec time gap using runnable interface
235 . Write a java program to display addition program and subtraction program with 2 sec time gap
236 . online Ticket Booking program without using Thread Synchronization
237 . Online Ticket Booking program with using synchronized method
238 . Online Ticket Booking program with using synchronized block
239 . Write a Thread setName() program
240 . Write a Thread getName() program


Threadstop
Threadstop
Threadstop
Threadstop
Threadstop
Threadstop