企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
#### 同步代码块 ``` synchronized(同步锁){       需要同步操作的代码 } ``` ``` public static class Ticker implements Runnable{ private int total = 100; // 同步锁 Object lock = new Object(); @Override public void run() { synchronized (lock){ //同步锁 while (true){ if (total > 0){ try { Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("tick total is = " + total--); } } } } } ```