如何在编写java同步代码时并行运行静态和非静态java同步方法?
public class Counter{
private static count = 0;
public static synchronized getCount()
{
return this.count;
}
public synchronized setCount(int count)
{
this.count = count;
}
}
Run Code Online (Sandbox Code Playgroud) 当一个线程调用一个synchronized方法时,它会自动获取该方法对象的内部锁,并在方法返回时释放它,但是当调用静态synchronized方法时会发生什么,因为静态方法与一个类而不是一个对象相关联?
java ×2