读书人

lt;lt;java并发编程gt;gt;读书笔记之线程间断

发布时间: 2012-10-27 10:42:26 作者: rapoo

<<java并发编程>>读书笔记之线程中断

 public void put(E e) throws InterruptedException {        if (e == null) throw new NullPointerException();        final E[] items = this.items;        final ReentrantLock lock = this.lock;        lock.lockInterruptibly();        try {            try {              while (count == items.length)                    notFull.await();                       } catch (InterruptedException ie) {                notFull.signal(); // propagate to non-interrupted thread                throw ie;            }            insert(e);        } finally {            lock.unlock();        }    }

我们指定的capacity的是1,也就是当count和items.length相等的时候,这个queue会被阻塞。
问题就在于:当生产者线程的put>take,这个时候queue会被很快填满.此时如果take速度比较慢,并且signal中断,这个时候是没有办法停止的,除非当take到最后一个的时候,该线程才会退出。

读书人网 >编程

热点推荐