package thread_1.safe8; import lombok.Getter; public class Counter { @Getter private static int count = 0; // 静态同步方法 public synchronized static void increment() { count++; } public static void main(String[] args) throws InterruptedException { // 创建多个线程调用静态同步方法 Thread t1 = new Thread(() -> { for (int i = 0; i < 1000; i++) { Counter.increment(); // 调用静态同步方法 } }); Thread t2 = new Thread(() -> { for (int i = 0; i < 1000; i++) { Counter.increment(); // 调用静态同步方法 } }); t1.start(); t2.start(); t1.join(); t2.join(); System.out.println("Final count: " + Counter.getCount()); } }