Space for google add

Write a program that create 2 threads – each displaying a message.

 Write a program that create 2 threads – each displaying a message (Pass the message

as a parameter to the constructor). The threads should display the messages continuously

till the user presses ctrl-c. Also display the thread information as it is running.


import java.io.*;
class A extends Thread
{
    String s=null;
    A(String s)
    {
        this.s=s;
           
    }
   
        public void run()
    {
        try
        {
            while(true)
            {
                System.out.println(s);
            }
        }
        catch(Exception e)
        {
            System.out.println(e);
        }
    }
}


class seta1
{
    public static void main(String args[])
    {
        A a=new A("First Thread Running");
        A a1=new A("Second Thread Running");
        System.out.println(a);
        System.out.println(a1);
        a.start();
        a1.start();
       
       
    }
}

Post a Comment

0 Comments