当从文件内容填充队列时,深度似乎不会增加,因为在此实现中未添加元素。队列满,深度阻塞队列,需要澄清
BlockingQueue<String> q = new SynchronousQueue<String>();
...
fstream = new FileInputStream("/path/to/file.txt");
...
while ((line = br.readLine()) != null) {
if (q.offer(line))
System.out.println("Depth: " + q.size()); //0
}
当add
更换offer
,异常,如果抛出
Exception in thread "main" java.lang.IllegalStateException: Queue full
...
什么我做错了吗?为什么插入第一个元素后,队列立即满了?
RTFM ftw。谢谢你。将在10分钟内接受 – JAM 2012-02-05 18:43:56
实际上,由于没有空气呼吸,您甚至无法在有同步队列的情况下呼吸。同步队列是一切,什么都不是,它无处不在。单纯地球居民无法理解同步队列的形而上学意义。 – Tudor 2012-02-05 18:48:01