普通方法安全修饰:
public synchronized void fun(){ }静态方法安全修饰:
public synchronized static void fun(){ }方法内安全修饰:
public class A{ Object o = new Object();//锁对象 public void fun(){ synchronized(o){ //同步代码 } } }类安全修饰:
public class A{ public void fun(){ synchronized(A.class){ //同步代码 } } }