💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
``` public void lock() :加同步锁 public void unlock() :释放同步 ``` ``` public static class Ticker implements Runnable{ private int total = 100; Lock lock = new ReentrantLock(); @Override public void run() { while (true){ lock.lock(); sellTick(); lock.unlock(); } } //Lock锁 private void sellTick(){ if (total > 0){ try { Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("tick total is = " + total--); } } } ```