小编Nag*_*555的帖子

超出最大许可数:信号量

public class semaphoreTest {

static LinkedList<Integer> integerLinkedList = new LinkedList<>();
static Semaphore semaphore = new Semaphore(1);
static Object lock = new Object();

public static void main(String[] args) throws InterruptedException {
    Thread t1 = new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                produce();
            } catch (InterruptedException e) {
            }
        }
    });

    Thread t2 = new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                consume();
            } catch (InterruptedException e) {
            }
        }
    });

    t1.start();
    t2.start();

    t1.join();
    t2.join(); …
Run Code Online (Sandbox Code Playgroud)

java multithreading semaphore

2
推荐指数
1
解决办法
1124
查看次数

标签 统计

java ×1

multithreading ×1

semaphore ×1