买票

package com.wuhongyu.test1.test;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Thhhhh implements Runnable{
    private static int a = 100;
    Lock lock = new ReentrantLock();

    @Override
    public void run() {

        while (true) {
            try {
                lock.lock();
                if (a > 0) {
                    System.out.println(Thread.currentThread().getName()+":"+a);
                    a--;
                }
            }finally {
                lock.unlock();
            }

        }
    }
}

你可能感兴趣的:(买票)