Code example for ArrayBlockingQueue

Methods: add, drainTo, size

0
					+ event.values[1] * event.values[1] + event.values[2]
							* event.values[2]);
 
			// Add m to the mAccBuffer one by one. 
			try { 
				mAccBuffer.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>(
						mAccBuffer.size() * 2);
 
				mAccBuffer.drainTo(newBuf);
				mAccBuffer = newBuf;
				mAccBuffer.add(new Double(m));
			}  
		} 
	}