use of java.util.concurrent.LinkedBlockingQueue in project jmxtrans by jmxtrans.
the class JmxTransModule method createExecutorService.
private ThreadPoolExecutor createExecutorService(int poolSize, int workQueueCapacity, String componentName) {
BlockingQueue<Runnable> workQueue = new LinkedBlockingQueue<>(workQueueCapacity);
ThreadFactory threadFactory = threadFactory(componentName);
return new ThreadPoolExecutor(poolSize, poolSize, 0L, MILLISECONDS, workQueue, threadFactory);
}
use of java.util.concurrent.LinkedBlockingQueue in project Openfire by igniterealtime.
the class InternalComponentManager method query.
@Override
public IQ query(Component component, IQ packet, long timeout) throws ComponentException {
final LinkedBlockingQueue<IQ> answer = new LinkedBlockingQueue<>(8);
XMPPServer.getInstance().getIQRouter().addIQResultListener(packet.getID(), new IQResultListener() {
@Override
public void receivedAnswer(IQ packet) {
answer.offer(packet);
}
@Override
public void answerTimeout(String packetId) {
Log.warn("An answer to a previously sent IQ stanza was never received. Packet id: " + packetId);
}
});
sendPacket(component, packet);
IQ reply = null;
try {
reply = answer.poll(timeout, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
// Ignore
}
return reply;
}
use of java.util.concurrent.LinkedBlockingQueue in project Openfire by igniterealtime.
the class HttpSessionManager method start.
/**
* Starts the services used by the HttpSessionManager.
*
* (Re)creates and configures a pooled executor to handle async routing for incoming packets with a configurable
* (through property "xmpp.httpbind.worker.threads") amount of threads; also uses an unbounded task queue and
* configurable ("xmpp.httpbind.worker.timeout") keep-alive.
*
* Note: Apart from the processing threads configured in this class, the server also uses a threadpool to perform
* the network IO (as configured in ({@link HttpBindManager}). BOSH installations expecting heavy loads may want to
* allocate additional threads to this worker pool to ensure timely delivery of inbound packets
*/
public void start() {
Log.info("Starting instance");
this.sessionManager = SessionManager.getInstance();
final int maxClientPoolSize = JiveGlobals.getIntProperty("xmpp.client.processing.threads", 8);
final int maxPoolSize = JiveGlobals.getIntProperty("xmpp.httpbind.worker.threads", maxClientPoolSize);
final int keepAlive = JiveGlobals.getIntProperty("xmpp.httpbind.worker.timeout", 60);
sendPacketPool = new ThreadPoolExecutor(getCorePoolSize(maxPoolSize), maxPoolSize, keepAlive, TimeUnit.SECONDS, // unbounded task queue
new LinkedBlockingQueue<Runnable>(), new NamedThreadFactory("httpbind-worker-", true, null, Thread.currentThread().getThreadGroup(), null));
sendPacketPool.prestartCoreThread();
// Periodically check for Sessions that need a cleanup.
inactivityTask = new HttpSessionReaper();
TaskEngine.getInstance().schedule(inactivityTask, 30 * JiveConstants.SECOND, 30 * JiveConstants.SECOND);
}
use of java.util.concurrent.LinkedBlockingQueue in project mapdb by jankotek.
the class LinkedBlockingQueueTest method testEmptyFull.
/**
* Queue transitions from empty to full when elements added
*/
public void testEmptyFull() {
LinkedBlockingQueue q = new LinkedBlockingQueue(2);
assertTrue(q.isEmpty());
assertEquals("should have room for 2", 2, q.remainingCapacity());
q.add(one);
assertFalse(q.isEmpty());
q.add(two);
assertFalse(q.isEmpty());
assertEquals(0, q.remainingCapacity());
assertFalse(q.offer(three));
}
use of java.util.concurrent.LinkedBlockingQueue in project mapdb by jankotek.
the class LinkedBlockingQueueTest method testTimedOffer.
/**
* timed offer times out if full and elements not taken
*/
public void testTimedOffer() {
final LinkedBlockingQueue q = new LinkedBlockingQueue(2);
final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
Thread t = newStartedThread(new CheckedRunnable() {
public void realRun() throws InterruptedException {
q.put(new Object());
q.put(new Object());
long startTime = System.nanoTime();
assertFalse(q.offer(new Object(), timeoutMillis(), MILLISECONDS));
assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
pleaseInterrupt.countDown();
try {
q.offer(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS);
shouldThrow();
} catch (InterruptedException success) {
}
}
});
await(pleaseInterrupt);
assertThreadStaysAlive(t);
t.interrupt();
awaitTermination(t);
}
Aggregations