Wednesday, June 2, 2021

Create two threads in which one displays “Dept of CSE” for every 2 seconds and the other displays “ Jain University” for every 4 seconds continuously.

PROGRAM :

package com.company;

class Thread1 extends Thread

{

    public void run()

    {

 

        try

        {

            while(true)

            {

                System.out.println( "Department of CSE");

 

                Thread.sleep(2000);

            }

        }

        catch (InterruptedException interruptedException)

        {

            System.out.println(  "First Thread is interrupted when it is  sleeping" +interruptedException);

        }

    }

}

 

class Thread2 extends Thread

{

    public void run()

    {

 

        try

        {

            while(true)

            {

                System.out.println( "JAIN University");

                Thread.sleep(4000);

            }

        }

        catch (InterruptedException interruptedException)

        {

            System.out.println(  "First Thread is interrupted when it is  sleeping" +interruptedException);

        }

    }

}

 

public class ThreadDemo13

{

    public static void main(String[] args)

    {

        Thread1 firstThread = new Thread1();

        Thread2 secondThread = new Thread2();

        firstThread.start();

        secondThread.start();

    }

}

OUTPUT :



Labels:

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home