List of usage examples for java.util.concurrent ArrayBlockingQueue ArrayBlockingQueue
public ArrayBlockingQueue(int capacity)
From source file:ch.cyberduck.core.transfer.TransferQueue.java
/** * Resize queue with current setting in preferences. *//*from www . java2s. co m*/ public void resize(int newsize) { if (log.isDebugEnabled()) { log.debug(String.format("Resize queue to %d", newsize)); } final int drained = running.drainTo(temporary); if (log.isDebugEnabled()) { log.debug(String.format("Drained %d elements", drained)); } running.clear(); running = new ArrayBlockingQueue<Transfer>(newsize); this.poll(); }
From source file:com.netflix.suro.client.async.AsyncSuroClient.java
@Inject public AsyncSuroClient(ClientConfig config, Queue4Client messageQueue, ConnectionPool connectionPool) { this.config = config; this.messageQueue = messageQueue; this.connectionPool = connectionPool; this.builder = new MessageSetBuilder(config).withCompression(Compression.create(config.getCompression())); poller.execute(createPoller());/*from ww w. j a v a 2 s. c om*/ jobQueue = new ArrayBlockingQueue<Runnable>(config.getAsyncJobQueueCapacity()) { @Override public boolean offer(Runnable runnable) { try { put(runnable); // not to reject the task, slowing down } catch (InterruptedException e) { // do nothing } return true; } }; senders = new ThreadPoolExecutor(config.getAsyncSenderThreads(), config.getAsyncSenderThreads(), 10, TimeUnit.SECONDS, jobQueue, new RejectedExecutionHandler() { @Override public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) { TMessageSet messageSet = ((AsyncSuroSender) r).getMessageSet(); for (Message m : new MessageSetReader(messageSet)) { restore(m); } } }); rateLimiter = new RateLimiter(rateLimitMsgPerSec.get()); tags = GraphitePublisher.createSimpleTagList(config.getApp() + "_" + config.getClientType() + "_client"); Monitors.registerObject(this); }
From source file:org.aksw.xoperator.Agent.java
private void registerComponents(MutablePicoContainer container) { container.addComponent(Controller.class, Controller.class, new Parameter[] { new ComponentParameter(Command.class, false), new BasicComponentParameter(), new BasicComponentParameter(), new BasicComponentParameter(), new BasicComponentParameter() }); container.addComponent(loadConfigurations()); container.addComponent(JabberClientManager.class); container.addComponent(SparqlEndpointFacade.class); container.addComponent(SimpleXslTransformer.class); container.addComponent(AimlFacade.class); container.addComponent(ExternalListenerGroovy.class); container.addComponent(SimpleSecurityProvider.class); container.addComponent(AliceBotFactory.class, AliceBotFactory.class, new Parameter[] { new BasicComponentParameter(), new ComponentParameter(ExternalListener.class, false) }); container.addComponent(LocalSparqlEndpoint.class); container.addComponent(RemoteSparqlEndpoint.class); container.addComponent(RosterManager.class); container.addComponent(P2PFacade.class); container.addComponent(/*w w w . ja v a 2 s. com*/ new ThreadPoolExecutor(5, 10, 60, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(100))); }
From source file:com.pinterest.rocksplicator.controller.WorkerPoolTest.java
@Test public void testAssignMultiTask() throws Exception { Semaphore idleWorkersSemaphore = new Semaphore(0); ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(2, 2, 0, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(1)); WorkerPool workerPool = new WorkerPool(threadPoolExecutor, idleWorkersSemaphore, new TaskQueue() { });/*from w w w.j av a 2 s . co m*/ workerPool.assignTask(getSleepIncrementTask()); workerPool.assignTask(getSleepIncrementTask()); workerPool.assignTask(getSleepIncrementTask()); Thread.sleep(1500); // Only expect 2 to finish because the pool size is 2 Assert.assertEquals(2, SleepIncrementTask.executionCounter.intValue()); Assert.assertEquals(2, idleWorkersSemaphore.availablePermits()); Thread.sleep(1000); }
From source file:net.opentsdb.tsd.GraphHandler.java
/** * Constructor./*w w w . j a va 2 s.c om*/ */ public GraphHandler() { // Gnuplot is mostly CPU bound and does only a little bit of IO at the // beginning to read the input data and at the end to write its output. // We want to avoid running too many Gnuplot instances concurrently as // it can steal a significant number of CPU cycles from us. Instead, we // allow only one per core, and we nice it (the nicing is done in the // shell script we use to start Gnuplot). Similarly, the queue we use // is sized so as to have a fixed backlog per core. final int ncores = Runtime.getRuntime().availableProcessors(); gnuplot = new ThreadPoolExecutor(ncores, ncores, // Thread pool of a fixed size. /* 5m = */ 300000, MILLISECONDS, // How long to keep idle threads. new ArrayBlockingQueue<Runnable>(20 * ncores), // XXX Don't hardcode? thread_factory); // ArrayBlockingQueue does not scale as much as LinkedBlockingQueue in terms // of throughput but we don't need high throughput here. We use ABQ instead // of LBQ because it creates far fewer references. }
From source file:com.pinterest.rocksplicator.controller.DispatcherTest.java
@Test public void testingMultiTasks() throws Exception { sleepTimeMillis = 3000;/*from w w w .j a v a 2 s . co m*/ PowerMockito.when(taskQueue.dequeueTask(anyString())).thenReturn(getSleepIncrementTaskFromQueue()) .thenReturn(getSleepIncrementTaskFromQueue()).thenReturn(getSleepIncrementTaskFromQueue()) .thenReturn(null); sleepTimeMillis = 3000; Semaphore idleWorkersSemaphore = new Semaphore(2); ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(2, 2, 0, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(2)); WorkerPool workerPool = new WorkerPool(threadPoolExecutor, idleWorkersSemaphore, taskQueue); TaskDispatcher dispatcher = new TaskDispatcher(2, idleWorkersSemaphore, workerPool, taskQueue); dispatcher.start(); synchronized (SleepIncrementTask.notifyObject) { SleepIncrementTask.notifyObject.wait(); SleepIncrementTask.notifyObject.wait(); } Assert.assertTrue(SleepIncrementTask.executionCounter.intValue() <= 3); Assert.assertTrue(SleepIncrementTask.executionCounter.intValue() >= 2); dispatcher.stop(); }
From source file:org.apache.hadoop.hdfs.job.MyJob_20110926.java
public MyJob_20110926(NameNode nameNode, Configuration conf) { this(nameNode, null, conf, new ArrayBlockingQueue<Job>(conf.getInt("hdfs.job.tatol", 20)), true); }
From source file:org.htrace.impl.ZipkinSpanReceiver.java
public ZipkinSpanReceiver() { this.queue = new ArrayBlockingQueue<Span>(1000); this.protocolFactory = new TBinaryProtocol.Factory(); tf = new ThreadFactoryBuilder().setDaemon(true).setNameFormat("zipkinSpanReceiver-%d").build(); }
From source file:org.apache.hadoop.yarn.server.security.CertificateLocalizationService.java
public CertificateLocalizationService(ServiceType service) { super(CertificateLocalizationService.class.getName()); this.service = service; localizationEventsQ = new ArrayBlockingQueue<>(100); }
From source file:com.kurento.kmf.media.PointerDetectorFilterTest.java
/** * @throws InterruptedException/*from w w w .j a va2 s . c o m*/ * */ @Test public void testWindowOverlay() throws InterruptedException { PointerDetectorWindowMediaParam window0 = new PointerDetectorWindowMediaParam("window0", 50, 50, 200, 50); filter.addWindow(window0); final BlockingQueue<WindowInEvent> eventsIn = new ArrayBlockingQueue<WindowInEvent>(1); final BlockingQueue<WindowOutEvent> eventsOut = new ArrayBlockingQueue<WindowOutEvent>(1); filter.addWindowInListener(new MediaEventListener<WindowInEvent>() { @Override public void onEvent(WindowInEvent event) { eventsIn.add(event); } }); filter.addWindowOutListener(new MediaEventListener<WindowOutEvent>() { @Override public void onEvent(WindowOutEvent event) { eventsOut.add(event); } }); player.play(); Assert.assertNotNull(eventsIn.poll(10, TimeUnit.SECONDS)); Assert.assertNotNull(eventsOut.poll(5, TimeUnit.SECONDS)); player.stop(); }