Home > Java > javaTutorial > body text

What is the status of java thread execution?

WBOY
Release: 2023-04-18 09:55:02
forward
956 people have browsed it

1. If the queue is full, the new thread performing the put operation will be added to the notFull condition queue to wait.

2. The queue is not full. When a thread performs the operation of removing queue elements, the removal is successful and the put thread is awakened.

Example

    public E take() throws InterruptedException {
        final ReentrantLock lock = this.lock;
        lock.lockInterruptibly();
        try {
            // 队列长度为0
            while (count == 0)
                // 阻塞
                notEmpty.await();
            // 如果队列有元素执行删除操作
            return dequeue();
        } finally {
            lock.unlock();
        }
    }
/** Condition for waiting takes */
    private final Condition notEmpty;
Copy after login

The above is the detailed content of What is the status of java thread execution?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template