package com.zhl.practice; import org.junit.Test; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.concurrent.locks.ReentrantLock; /** *@author Holley * @Description 公平锁与非公平锁的演示 * @create 2019-05-16 10:16 **/publicclass LockTest {privatestatic ReenTrantLock2 fairLock =new ReenTrantLock2(true);privatestatic ReenTrantLock2 nonfairLock =new ReenTrantLock2(false); @Testpublicvoid fair(){ testLock(fairLock); } @Testpublicvoid unfair(){ testLock(nonfairLock); }privatevoid testLock(ReenTrantLock2 lock){for(int i = 0; i