简单公平锁实现
```
public class ReentrantLockDemo implements Runnable {
private static ReentrantLock lock = new ReentrantLock(true);
private String content;
public ReentrantLockDemo(String content) {
this.content = content;
}
@
Override public void run() {
while (true) {
try {
lock.lock();
System.out.println(content);
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
lock.unlock();
}
}
}
public static void main(String[] args) {
ReentrantLockDemo a = new ReentrantLockDemo("a");
ReentrantLockDemo b = new ReentrantLockDemo("b");
ReentrantLockDemo c = new ReentrantLockDemo("c");
Thread threadA = new Thread(a);
Thread threadB = new Thread(b);
Thread threadC = new Thread(c);
threadA.start();
threadB.start();
threadC.start();
}
}
```