Syncronized blocks

PHOTO EMBED

Wed Jan 24 2024 11:35:39 GMT+0000 (Coordinated Universal Time)

Saved by @E23CSEU1151 #java

class Msg
{
    public void Show(String name)
    {
        ;;;;; // 100 line code

        synchronized(this)
        {
            for(int i = 1; i <= 3; i++)
            {
                System.out.println("how are you " + name);
            }
        }
        ;;;;; // 100 line code
    }
}

class Ourthread extends Thread
{
    Msg m;
    String name;

    Ourthread(Msg m, String name)
    {
        this.m = m;
        this.name = name;
    }

    public void run()
    {
        m.Show(name);
    }
}

class Death
{
    public static void main(String[] args)
    {
        Msg msg = new Msg(); // Create an instance of the Msg class
        Ourthread t1 = new Ourthread(msg, "om");
        Ourthread t2 = new Ourthread(msg, "harry");

        t1.start();
        t2.start();
    }
}
content_copyCOPY