package com.basic; import java.util.concurrent.locks.ReentrantLock; /** * @program JavaBooks * @description: ReentrantLockçå ¬å¹³é * @author: mf * @create: 2019/12/30 20:42 */ public class T14 { private static ReentrantLock lock = new ReentrantLock(true); // trueä¸ºå ¬å¹³é public void m() { for (int i = 0; i < 1000; i++) { lock.lock(); try { System.out.println(Thread.currentThread().getName() + "è·å¾é"); } catch (Exception e) { e.printStackTrace(); } finally { lock.unlock(); } } } public static void main(String[] args) { T14 t14 = new T14(); new Thread(t14::m, "t1").start(); new Thread(t14::m, "t2").start(); } }