30黑马币
最佳答案//以电影院售票为例:
//SellTickets售票方法继承自Thread
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
public class SellTickets extends Thread {
public static int tickets = 100 ;
// 创建锁对象
public static Lock lock = new ReentrantLock() ;
@Override
public void run() {
while(true){
// 加锁
lock.lock() ;
if(tickets > 0) ...
| |
| |