超时
中断;
生产者/消费者队列
public class Demo09 implements Runnable {
public static ReentrantLock lock = new ReentrantLock(); //锁 相当于一份公共资源
public static void main(String[] args) {
Thread t1 = new Thread(new Demo09());
Thread t2 = new Thread(new Demo09());
t1.start();
t2.start();
}
@Override
public void run() {
lock.lock(); // 获取锁
for(int j = 0; j < 3; j++) {
System.out.println(Thread.currentThread().getName() + " " + j);
}
lock.unlock(); // 释放锁
}
}