一 修饰方法或静态方法
public synchronized void method()
{
// todo
}
public synchronized static void method() {
// todo
}
二、修饰代码块
public void method()
{
synchronized(this) {
// todo
}
}
三、修饰对象
public class Count{
private Integer account;
public void increase(){
synchronized (Count.class){
account++;
}
}
}