I have following program in same file. I have synchronized the run() method.

class MyThread2 implements Runnable {
    Thread    t;

    MyThread2(String s) {
        t=new Thread(this,s);
        t.start();
    } 

    public synchronized  void  run() {
        for (int i=0;i<3;i++) {
            System.out.println("Thread name : "+ Thread.currentThread).getName());
            try {
                t.sleep(1000);
            }
            catch (InterruptedException e) {
                e.getMessage();
            }
        }
    }
}

class TestSync {
    public static void main(String[] args) {
        MyThread2 m1=new MyThread2("My Thread 1");
        c.fun();
    }
}

class c {
    static void fun() {
        MyThread2 m1=new MyThread2("My Thread 4");
    }
}

output is

Thread name : My Thread 1
Thread name : My Thread 4
Thread name : My Thread 4
Thread name : My Thread 1
Thread name : My Thread 1
Thread name : My Thread 4

My question is why is synchronized method allowing both "My Thread 1" and "My Thread 4" thread access concurrently?

Edit
Report