List of usage examples for java.util.concurrent SynchronousQueue SynchronousQueue
public SynchronousQueue()
From source file:org.apache.solr.client.solrj.TestBackupLBHttpSolrClient.java
@Override public void setUp() throws Exception { super.setUp(); httpClient = HttpClientUtil.createClient(null); HttpClientUtil.setConnectionTimeout(httpClient, 1000); solr = new HashMap<String, SolrInstance>(); commExecutor = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 5, TimeUnit.SECONDS, // terminate idle threads after 5 sec new SynchronousQueue<Runnable>(), // directly hand off tasks new DefaultSolrThreadFactory("TestBackupLBHttpSolrServer")); }
From source file:org.apache.activemq.JmsConnectionStartStopTest.java
public void testConcurrentSessionCreateWithStart() throws Exception { ThreadPoolExecutor executor = new ThreadPoolExecutor(50, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>()); final Vector<Throwable> exceptions = new Vector<Throwable>(); final Random rand = new Random(); Runnable createSessionTask = new Runnable() { @Override//from w w w.ja va 2 s . co m public void run() { try { TimeUnit.MILLISECONDS.sleep(rand.nextInt(10)); stoppedConnection.createSession(false, Session.AUTO_ACKNOWLEDGE); } catch (Exception e) { exceptions.add(e); } } }; Runnable startStopTask = new Runnable() { @Override public void run() { try { TimeUnit.MILLISECONDS.sleep(rand.nextInt(10)); stoppedConnection.start(); stoppedConnection.stop(); } catch (Exception e) { exceptions.add(e); } } }; for (int i = 0; i < 1000; i++) { executor.execute(createSessionTask); executor.execute(startStopTask); } executor.shutdown(); assertTrue("executor terminated", executor.awaitTermination(30, TimeUnit.SECONDS)); assertTrue("no exceptions: " + exceptions, exceptions.isEmpty()); }
From source file:org.esigate.extension.parallelesi.Esi.java
@Override public void init(Driver driver, Properties properties) { driver.getEventManager().register(EventManager.EVENT_RENDER_PRE, this); driver.getEventManager().register(Surrogate.EVENT_SURROGATE_CAPABILITIES, new IEventListener() { @Override//from w w w.ja v a2 s . co m public boolean event(EventDefinition id, Event event) { CapabilitiesEvent capEvent = (CapabilitiesEvent) event; for (String capability : CAPABILITIES) { capEvent.getCapabilities().add(capability); } return true; } }); // Load configuration this.maxThreads = THREADS.getValue(properties); this.idle = IDLE.getValue(properties); if (this.maxThreads == 0) { this.executor = null; LOG.info("Linear ESI processing enabled."); } else { this.executor = new ThreadPoolExecutor(0, this.maxThreads, this.idle, TimeUnit.SECONDS, new SynchronousQueue<Runnable>()); LOG.info("Multi-threaded ESI processing enabled. Thread limit: {}, max idle {}.", String.valueOf(this.maxThreads), String.valueOf(this.idle)); } }
From source file:org.hyperledger.fabric.sdk.HFClient.java
private HFClient() { executorService = new ThreadPoolExecutor(CLIENT_THREAD_EXECUTOR_COREPOOLSIZE, CLIENT_THREAD_EXECUTOR_MAXIMUMPOOLSIZE, CLIENT_THREAD_EXECUTOR_KEEPALIVETIME, CLIENT_THREAD_EXECUTOR_KEEPALIVETIMEUNIT, new SynchronousQueue<Runnable>(), r -> { Thread t = threadFactory.newThread(r); t.setDaemon(true);// ww w .jav a 2 s. c o m return t; }); }
From source file:org.rifidi.edge.core.sensors.sessions.AbstractServerSocketSensorSession.java
@Override protected void _connect() throws IOException { if (serverSocketPort < 1) { logger.info("Not starting server socket, since port < 1"); return;/*from w w w .j a v a 2 s. c om*/ } if (getStatus() == SessionStatus.CONNECTING || getStatus() == SessionStatus.PROCESSING) { logger.warn("Session already started"); return; } setStatus(SessionStatus.CONNECTING); // create a new executor service that will handle each new request. Use // SynchronousQueue so that tasks will be rejected if there is no free // worker thread available executorService = new ThreadPoolExecutor(0, maxNumSensors, 5, TimeUnit.MINUTES, new SynchronousQueue<Runnable>()); // open up server socket try { serverSocket = new ServerSocket(serverSocketPort); } catch (IOException e) { logger.error("Cannot start Alient Autonomous Sensor"); disconnect(); throw e; } logger.info(sensor.getID() + " listening on port " + serverSocket.getLocalPort() + ". Maximum number of concurrent readers supported: " + maxNumSensors); setStatus(SessionStatus.PROCESSING); // while session is not closed, process each request while (!executorService.isShutdown()) { try { // wait on a new request Socket clientSocket = serverSocket.accept(); logger.info("Accepted client at " + clientSocket.getInetAddress()); // give the socket to the handler to do the dirty work ServerSocketSensorSessionReadThread handler = new ServerSocketSensorSessionReadThread(clientSocket, getMessageParsingStrategyFactory(), getMessageProcessingStrategyFactory()); try { executorService.execute(handler); } catch (RejectedExecutionException e) { logger.warn("Cannot create a handler thread for socket " + clientSocket.getInetAddress(), e); clientSocket.close(); } } catch (IOException e) { // print an error message if we weren't the ones who caused the // problem if (!executorService.isShutdown()) { logger.error("Failed to start Alien Autonomous Handler", e); } } } logger.info("Stopping " + sensor.getID()); setStatus(SessionStatus.CREATED); }
From source file:com.netflix.blitz4j.LoggingConfiguration.java
private LoggingConfiguration() { ThreadFactory threadFactory = new ThreadFactoryBuilder().setDaemon(false) .setNameFormat("DynamicLog4jListener").build(); this.executorPool = new ThreadPoolExecutor(0, 1, 15 * 60, TimeUnit.SECONDS, new SynchronousQueue(), threadFactory);/* w w w . j av a 2 s . c om*/ }
From source file:org.apache.solr.client.solrj.TestBackupLBHttpSolrServer.java
@Override public void setUp() throws Exception { super.setUp(); httpClient = HttpClientUtil.createClient(null); HttpClientUtil.setConnectionTimeout(httpClient, 1000); inFlightRequestMonitor = new InflightRequestMonitor(false); solr = new HashMap<String, SolrInstance>(); commExecutor = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 5, TimeUnit.SECONDS, // terminate idle threads after 5 sec new SynchronousQueue<Runnable>(), // directly hand off tasks new DefaultSolrThreadFactory("TestBackupLBHttpSolrServer")); }
From source file:org.isharding.shard.strategy.access.impl.ParallelShardAccessStrategy.java
private ThreadPoolExecutor buildThreadPoolExecutor() { return new ThreadPoolExecutor(10, 50, 60, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), FACTORY); }
From source file:natalia.dymnikova.util.ThreadPoolBeans.java
public ExecutorService backgroundTasksExecutor0() { final ThreadFactory factory = new ThreadFactoryBuilder().setNameFormat("background-%03d").setDaemon(true) .build();/*from w w w. j a va2 s.com*/ final ExecutorService executor = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new SynchronousQueue<>(), factory); log.debug("Constructed background tasks executor {}", executor); return executor; }
From source file:org.apache.hedwig.server.netty.TestPubSubServer.java
@Test(timeout = 60000) public void testUncaughtExceptionInNettyThread() throws Exception { SynchronousQueue<Throwable> queue = new SynchronousQueue<Throwable>(); RecordingUncaughtExceptionHandler uncaughtExceptionHandler = new RecordingUncaughtExceptionHandler(queue); final int port = PortManager.nextFreePort(); PubSubServer server = startServer(uncaughtExceptionHandler, port, new TopicManagerInstantiator() { @Override//from w ww. j a va 2 s .c o m public TopicManager instantiateTopicManager() throws IOException { return new AbstractTopicManager(new ServerConfiguration(), Executors.newSingleThreadScheduledExecutor()) { @Override protected void realGetOwner(ByteString topic, boolean shouldClaim, Callback<HedwigSocketAddress> cb, Object ctx) { throw new RuntimeException("this exception should be uncaught"); } @Override protected void postReleaseCleanup(ByteString topic, Callback<Void> cb, Object ctx) { } }; } }); runPublishRequest(port); assertEquals(RuntimeException.class, queue.take().getClass()); server.shutdown(); }