对于以下程序代码:
public class ExamSyn1 implements Runnable {
int a = 0;
synchronized void m1( ) throws InterruptedException {
a = 1000;
Thread.sleep(500);
System.out.println("a=" + a);
}
synchronized void m2( ) throws InterruptedException {
Thread.sleep(250);
a = 2000;
}
public static void main(String[ ] args) throws InterruptedException {
ExamSyn1 tt = new ExamSyn1( );
Thread t = new Thread(tt);
t.start( );
tt.m2( );
System.out.println("main a=" + tt.a);
Thread.sleep(2000);
}
@Override
public void run( ) {
try {
m1( );
} catch (InterruptedException e) {
e.printStackTrace( );
}
}
}
对于以下输出结果,正确的是( )
main a= 结果1
a= 结果2