我写c/c++代码时,可以通过调试观察每条语句,可是这java代码该怎么研究
每条代码的意思,哪位大神讲讲这运行结果是怎么来的?
class MyValue
{
private int data;
public void m()
{
int result=0;
result+=2;
data+=2;
System.out.println(result+" "+data);
}
}
class MyThread extends Thread
{
private MyValue mv;
public MyThread(MyValue mv)
{
this.mv=mv;
}
public void run()
{
synchronized(mv)
{
mv.m();
}
}
}
public class TestMyThread
{
public static void main(String args[])
{
MyValue mv=new MyValue();
Thread t1=new MyThread(mv);
Thread t2=new MyThread(mv);
Thread t3=new MyThread(mv);
//t1.start();
//t2.start();
t3.start();
}
}