|
30 | 30 | public class BatchProcessor {
|
31 | 31 |
|
32 | 32 | private static final Logger LOG = Logger.getLogger(BatchProcessor.class.getName());
|
33 |
| - protected final BlockingQueue<AbstractBatchEntry> queue = new LinkedBlockingQueue<>(); |
| 33 | + protected final BlockingQueue<AbstractBatchEntry> queue; |
34 | 34 | private final ScheduledExecutorService scheduler;
|
35 | 35 | final InfluxDBImpl influxDB;
|
36 | 36 | final int actions;
|
@@ -171,6 +171,11 @@ public static Builder builder(final InfluxDB influxDB) {
|
171 | 171 | this.flushIntervalUnit = flushIntervalUnit;
|
172 | 172 | this.flushInterval = flushInterval;
|
173 | 173 | this.scheduler = Executors.newSingleThreadScheduledExecutor(threadFactory);
|
| 174 | + if (actions > 1 && actions < Integer.MAX_VALUE) { |
| 175 | + this.queue = new LinkedBlockingQueue<>(actions); |
| 176 | + } else { |
| 177 | + this.queue = new LinkedBlockingQueue<>(); |
| 178 | + } |
174 | 179 | // Flush at specified Rate
|
175 | 180 | this.scheduler.scheduleAtFixedRate(new Runnable() {
|
176 | 181 | @Override
|
@@ -238,7 +243,11 @@ void write() {
|
238 | 243 | * the batchEntry to write to the cache.
|
239 | 244 | */
|
240 | 245 | void put(final AbstractBatchEntry batchEntry) {
|
241 |
| - this.queue.add(batchEntry); |
| 246 | + try { |
| 247 | + this.queue.put(batchEntry); |
| 248 | + } catch (InterruptedException e) { |
| 249 | + throw new RuntimeException(e); |
| 250 | + } |
242 | 251 | if (this.queue.size() >= this.actions) {
|
243 | 252 | this.scheduler.submit(new Runnable() {
|
244 | 253 | @Override
|
|
0 commit comments