i am in a strange problem the code below creates two threads which try to execute synchronized method prin in class M1 but the threads are executing it simultaneously not after one
thread finishes, please explain this behaviour
class M2 implements Runnable{
public M2(){
Thread t=new Thread(this);
t.start();}
public void run(){
M1 k=new M1();
k.prin();}
}
class M3 implements Runnable{
public M3(){
Thread t=new Thread(this);
t.start();}
public void run(){
M1 k=new M1();
k.prin();}
}
public class M1{
synchronized void prin(){
for (int i=0;i<1000;i++)
{System.out.print(i+" "); }
System.out.println("HELLO");
System.out.println("HOW ARE");
System.out.println("YOU ?");
}
public static void main(
String ag[]){
M2 m=new M2();
M3 mm=new M3();
}
}