import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; public class ConcurrentLockExample { private static Lock lock = new ReentrantLock(); public static void main(String[] args) { Thread thread1 = new Thread(() -> { lock.lock(); try { } finally { lock.unlock(); } }); Thread thread2 = new Thread(() -> { lock.lock(); try { } finally { lock.unlock(); } }); thread1.start(); thread2.start(); } }


上一篇:
下一篇:
切换中文