【发布时间】:2015-12-28 16:35:01
【问题描述】:
假设我有一个类,其中的方法按如下方式同步。
public class Test{
public static synchronized void method1(){
}
public static synchronized void method2(){
}
public synchronized void method3(){
}
public synchronized void method4(){
}
}
所以有一个场景,两个线程同时调用method1和method2,感觉只允许调用其中一个方法,如果调用method1和method3会是什么情况.这里也会有同样的情况吗?method3 和 method4 来自同一个对象会是什么情况?
【问题讨论】:
-
你可以试试。如果你同时从两个不同的地方调用同步方法,两个调用都会一个接一个地完成(afaik)。
标签: java multithreading synchronization locking