@@ -0,0 +1,1833 @@
+package weatherhandler.processor;%0A%0Aimport java.util.List;%0Aimport java.util.ArrayList;%0A%0Aimport weatherhandler.data.Measurement;%0A%0A/**%0A * Processor that batches updates together in larger chunks for possibly quicker%0A * further processing. It does _NOT_ guarantee that exactly %60batchSize%60 updates%0A * are passed through--just that _AT LEAST_ %60batchSize%60 updates are passed%0A * through to the next processor.%0A */%0Apublic class BatchUpdatesProcessor implements Processor %7B%0A    // Default amount of measurements per batch%0A    final private static int DEFAULT_BATCH_SIZE = 1000;%0A    // Added to initial list size to avoid resizing the allocated list when only%0A    // a few too many items come in at once%0A    final private int BATCH_BUFFER = 50;%0A%0A    // Amount of Measurements per batch%0A    private int batchSize;%0A    // Current batch%0A    private List%3CMeasurement%3E batch;%0A    // Processor to pass batched data to%0A    private Processor next;%0A%0A    public BatchUpdatesProcessor(Processor next) %7B%0A        this(DEFAULT_BATCH_SIZE, next);%0A    %7D%0A    public BatchUpdatesProcessor(int batchSize, Processor next) %7B%0A        this.next = next;%0A        this.batchSize = batchSize;%0A        this.batch = new ArrayList%3CMeasurement%3E(batchSize + BATCH_BUFFER);%0A    %7D%0A%0A    /**%0A     * Batch & push new updates.%0A     */%0A    public void processMeasurements(List%3CMeasurement%3E measurements) throws ProcessorException %7B%0A        this.batch.addAll(measurements);%0A        if (this.batch.size() %3E= this.batchSize) %7B%0A            // Replace batch by a new list immediately, so threads can read from%0A            // this batch and other threads can write to the next batch%0A            List%3CMeasurement%3E current = this.batch;%0A            this.batch = new ArrayList%3CMeasurement%3E(this.batchSize + BATCH_BUFFER);%0A            this.next.processMeasurements(current);%0A        %7D%0A    %7D%0A%7D%0A

add Batch processor for large & speedy DB inserts