List of usage examples for java.util.concurrent ArrayBlockingQueue ArrayBlockingQueue
public ArrayBlockingQueue(int capacity)
From source file:io.kahu.hawaii.util.call.dispatch.HawaiiExecutorImpl.java
public HawaiiExecutorImpl(String name, int corePoolSize, int maximumPoolSize, int queueSize, TimeOut threadKeepAlive, LogManager logManager) { this(name, corePoolSize, maximumPoolSize, threadKeepAlive, new ArrayBlockingQueue<>(queueSize), new HawaiiThreadFactory(name), null, logManager); }
From source file:com.pinterest.rocksplicator.controller.WorkerPoolTest.java
@Test public void testAssignSingleTask() throws Exception { Semaphore idleWorkersSemaphore = new Semaphore(0); ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(1, 1, 0, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(1)); WorkerPool workerPool = new WorkerPool(threadPoolExecutor, idleWorkersSemaphore, new TaskQueue() { });//from w w w. j a v a 2 s. c o m workerPool.assignTask(getSleepIncrementTask()); Thread.sleep(2000); Assert.assertEquals(1, SleepIncrementTask.executionCounter.intValue()); workerPool.assignTask(getSleepIncrementTask()); Thread.sleep(2000); Assert.assertEquals(2, SleepIncrementTask.executionCounter.intValue()); Assert.assertEquals(2, idleWorkersSemaphore.availablePermits()); }
From source file:org.openspaces.remoting.scripting.cache.BlockingQueueCompiledScriptPool.java
public void init(LocalScriptExecutor executor, Script script) throws ScriptingException { this.executor = executor; queue = new ArrayBlockingQueue<Object>(size); for (int i = 0; i < size; i++) { queue.add(executor.compile(script)); }//from w w w . j a v a 2 s . c o m }
From source file:oz.hadoop.yarn.api.net.ByteBufferPool.java
/** * //from w ww . ja v a2 s. co m * @param initialBufferSize * @param bufferCount */ public ByteBufferPool(int initialBufferSize, int bufferCount) { this.initialBufferSize = initialBufferSize; this.bufferQueue = new ArrayBlockingQueue<>(bufferCount); }
From source file:me.schiz.jmeter.ring.udp.EventLoopRunnable.java
public EventLoopRunnable(Ring ring) { this.ring = ring; byteBuffer = ByteBuffer.allocateDirect(ring.getBufferSize()); registerQueue = new ArrayBlockingQueue<KeyValue>(REGS_PER_ITERATION * 4); try {/* www .j a va2 s .c om*/ this.selector = Selector.open(); } catch (IOException e) { log.error("Can't open selector", e); } }
From source file:org.paxle.se.index.lucene.impl.LuceneWriterTest.java
@Override protected void setUp() throws Exception { super.setUp(); // a dummy indexer-input-queue this.queue = new ArrayBlockingQueue<ICommand>(5); this.dataSource = new DummySource(); // create a dummy command tracker this.cmdTracker = mock(ICommandTracker.class); // create an index writer this.writer = new LuceneWriter() { {//from w ww . j a v a 2 s . c om this.manager = lmanager; this.stopwordsManager = LuceneWriterTest.this.stopwordsManager; this.commandTracker = LuceneWriterTest.this.cmdTracker; this.activate(null); } }; this.writer.setDataSource(this.dataSource); }
From source file:MdDetect.java
/** * Set up a ThreadPoolExecutor to process files in parallel * * @param capacity pool size/*www. java2s .c om*/ */ private static void initExecutor(int capacity) { executorService = new ThreadPoolExecutor(1, // min pool size Runtime.getRuntime().availableProcessors() * 4, // max pool shouldn't exceed cores 2, // how many * how long? TimeUnit.SECONDS, // unit of time new ArrayBlockingQueue<Runnable>(capacity // initialize the list with a finite capacity )); }
From source file:org.springframework.integration.ftp.QueuedFtpClientPool.java
/** * @param maxPoolSize the maximum size of the pool */// w w w .j a v a 2 s .c o m public QueuedFtpClientPool(int maxPoolSize, FtpClientFactory factory) { Assert.notNull(factory); this.factory = factory; pool = new ArrayBlockingQueue<FTPClient>(maxPoolSize); }
From source file:cn.clxy.codes.upload.UploadFileService.java
private void doUpload(final List<Integer> indexes) { log.debug("Start! ===--------------------"); BlockingQueue<Part> parts = new ArrayBlockingQueue<Part>(Config.MAX_READ); CompletionService<String> cs = new ExecutorCompletionService<String>(executor); log.debug("Reading started."); cs.submit(new ReadTask(file, indexes, parts)); log.debug("Uploading started."); for (int i = 0; i < Config.MAX_UPLOAD; i++) { cs.submit(new UploadTask("upload." + i, uploader, parts)); }//from w w w . j a v a 2 s . c o m // Wait all done. total count = maxUpload + 1. for (int i = 0; i <= Config.MAX_UPLOAD; i++) { Future<String> future = null; try { future = cs.take(); checkFuture(future); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } // Notify sever all done. Future<String> result = executor.submit(new NotifyTask(file, uploader)); checkFuture(result); log.debug("End! ===--------------------"); }
From source file:org.apache.flink.streaming.api.streamcomponent.StreamIterationSource.java
@SuppressWarnings("rawtypes") public StreamIterationSource() { outputHandler = new OutputHandler(); numSources = newComponent();/*w w w.ja v a 2s . c om*/ instanceID = numSources; dataChannel = new ArrayBlockingQueue<StreamRecord>(1); }