List of usage examples for java.util.concurrent ArrayBlockingQueue drainTo
public int drainTo(Collection<? super E> c, int maxElements)
From source file:Main.java
public static void main(String[] argv) throws Exception { List<Integer> list = new ArrayList<Integer>(); int capacity = 100; ArrayBlockingQueue<Integer> queue = new ArrayBlockingQueue<Integer>(capacity); queue.put(0);//w ww.j a v a 2 s.c o m queue.put(1); queue.put(2); queue.drainTo(list, 3); System.out.println(queue); System.out.println(list); }
From source file:org.codice.ddf.commands.catalog.IngestCommand.java
private void submitToCatalog(ScheduledExecutorService batchScheduler, ExecutorService executorService, ArrayBlockingQueue<Metacard> metacardQueue, CatalogFacade catalog, long start) { batchScheduler.scheduleWithFixedDelay(() -> { int queueSize = metacardQueue.size(); if (queueSize > 0) { ArrayList<Metacard> metacardBatch = new ArrayList<>(batchSize); if (queueSize > batchSize || doneBuildingQueue.get()) { metacardQueue.drainTo(metacardBatch, batchSize); processingThreads.incrementAndGet(); }//from w w w . jav a2 s . c o m if (metacardBatch.size() > 0) { executorService.submit(() -> { try { processBatch(catalog, metacardBatch); } catch (SourceUnavailableException e) { if (INGEST_LOGGER.isWarnEnabled()) { INGEST_LOGGER.warn("Error on process batch: {}", e); } } }); printProgressAndFlush(start, fileCount.get(), ingestCount.get() + ignoreCount.get()); } } }, 100, 100, TimeUnit.MILLISECONDS); }