一、锁的类型
对象锁 :synchronized(xx.class) 、修饰静态方法
类锁 : synchronized(this) 、修饰普通方法
二、修饰对象
1、修饰普通方法
public synchronized void fun(){}
2、修饰静态方法
public synchronized static void fun(){}
3、修饰代码块
// 注意this 表示当前对象public void fun(){try {// synchronized(xxx.class)synchronized (this) {System.out.println("Method 2 execute");Thread.sleep(1000);}} catch (InterruptedException e) {e.printStackTrace();}}
