合规国际互联网加速 OSASE为企业客户提供高速稳定SD-WAN国际加速解决方案。 广告
#### 同步代码块 ``` 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--); } } } } } ```