public class TestObject{
public void synchronized method1(){
//some 1000 lines of code
}
public void method2(){
//some 1000 lines of code
}
}
假设有两个线程正在访问TestObject类的同一实例,我们称它们为t1和t2。我想知道以下情况会发生什么。
- t1正在访问method1()的中途。现在t2正在尝试访问method2()。
- t1正在访问method2()的中途。现在t2正在尝试访问method1()。
谢谢