When populating the queue from the contents of the file, depth does not seem to ever increase, as elements are not added in this implementation.
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
}
When replacing offer
with add
, exception if thrown
Exception in thread "main" java.lang.IllegalStateException: Queue full
...
What am i doing wrong please? Why is the queue full immediately, upon insertion of the first element?