首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

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

2012-10-27 
java并发编程读书笔记之线程中断public void put(E e) throws InterruptedException {if (e null)

<<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到最后一个的时候,该线程才会退出。

热点排行