Code example for ArrayBlockingQueue

Methods: add, drainTo, size

0
 
 
 
			// Add m to the mAccList one by one. 
			try { 
				mAccList.add(new Double(m));
			} catch (IllegalStateException e) {
 
				// Exception happens when reach the capacity. 
				// Doubling the buffer. ListBlockingQueue has no such issue, 
				// But generally has worse performance 
				ArrayBlockingQueue<Double> newBuf = new ArrayBlockingQueue<Double>(
						mAccList.size()*2);
				mAccList.drainTo(newBuf);
				mAccList = newBuf;
				mAccList.add(new Double(m));
 
			} 
		} 
	}