锁 synchronized synchronized锁的目标 对象 public class Test_Sync01 { Object o = new Object(); public void test() { synchronized (o) { System.out.println("o is synchronzied"); } } } this或者方法体。它们锁的都是当前对象。 public class Test_Sync02 { public synchronized void test() { System.out.println("function is start"); try { Thread.sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("function is synchronized"); } public void testThis() { synchronized (this) { System.out.println("this is synchronized"); } } public static void main(String[] args) throws InterruptedException { Test_Sync02 t = new Test_Sync02(); Thread t1 = new Thread( () -> t.test());t Thread t2 = new Thread( () -> t.testThis()); t1.start(); t2.star