List of usage examples for java.util.concurrent Executors newFixedThreadPool
public static ExecutorService newFixedThreadPool(int nThreads)
From source file:com.hunch.ImageManager.java
private static void startExecutor() { // if we already have an executor, theres no need for another one. if (executor != null) return;/*from w ww . j a va2 s. c om*/ if (Const.IMG_FETCH_THREADS > 1) executor = Executors.newFixedThreadPool(Const.IMG_FETCH_THREADS); else if (Const.IMG_FETCH_THREADS == 1) executor = Executors.newSingleThreadExecutor(); else executor = Executors.newCachedThreadPool(); }
From source file:com.calclab.emite.xtesting.services.HttpConnector.java
public HttpConnector() { sendService = Executors.newCachedThreadPool(); receiveService = Executors.newFixedThreadPool(1); }
From source file:com.espertech.esper.multithread.TestMTIsolation.java
private void tryIsolated(int numThreads, int numLoops) throws Exception { Configuration config = SupportConfigFactory.getConfiguration(); config.getEngineDefaults().getViewResources().setShareViews(false); config.addEventType("SupportBean", SupportBean.class); EPServiceProvider engine = EPServiceProviderManager.getDefaultProvider(config); engine.initialize();/*from w w w.j av a 2 s . c om*/ // execute ExecutorService threadPool = Executors.newFixedThreadPool(numThreads); Future future[] = new Future[numThreads]; ReentrantReadWriteLock sharedStartLock = new ReentrantReadWriteLock(); sharedStartLock.writeLock().lock(); for (int i = 0; i < numThreads; i++) { future[i] = threadPool.submit(new IsolateUnisolateCallable(i, engine, numLoops)); } Thread.sleep(100); sharedStartLock.writeLock().unlock(); threadPool.shutdown(); threadPool.awaitTermination(10, TimeUnit.SECONDS); for (int i = 0; i < numThreads; i++) { assertTrue((Boolean) future[i].get()); } }
From source file:org.opendaylight.sfc.sbrest.provider.task.SbRestSffTaskTest.java
@Before public void init() { executorService = Executors.newFixedThreadPool(10); }
From source file:ninja.eivind.hotsreplayuploader.files.AccountDirectoryWatcher.java
@Autowired public AccountDirectoryWatcher(StormHandler stormHandler) { watchDirectories = new HashSet<>(stormHandler.getReplayDirectories()); executor = Executors.newFixedThreadPool(watchDirectories.isEmpty() ? 1 : watchDirectories.size()); }
From source file:com.cisco.oss.foundation.monitoring.service.TestMultiService.java
@Test public void testManyServices() throws Exception { MonitoringAgentFactory.getInstance().register( new PropertiesConfiguration(TestMultiService.class.getResource("/config.properties").getPath())); ExecutorService threadPool = Executors.newFixedThreadPool(10); int numOfServices = 1234; final CountDownLatch latch = new CountDownLatch(numOfServices); final ServiceDetails serviceDetails = new ServiceDetails("default desc", "test", "junit", 12345); for (int i = 0; i < numOfServices; i++) { final int index = i; threadPool.execute(new Runnable() { @Override/* w ww. j av a 2s .c o m*/ public void run() { String apiName = (index % 3) + ""; CommunicationInfo.getCommunicationInfo().transactionStarted(serviceDetails, apiName, 125); try { Thread.sleep(2); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } CommunicationInfo.getCommunicationInfo().transactionFinished(serviceDetails, apiName, (index % 2 == 0) ? false : true, "kuku"); latch.countDown(); } }); } try { latch.await(); } catch (InterruptedException e) { e.printStackTrace(); } int numberOfThreads = Thread.getAllStackTraces().keySet().size(); Assert.assertTrue(numberOfThreads <= 30); try { Thread.sleep(1500); } catch (InterruptedException e) { e.printStackTrace(); } Collection<Service> services = ServiceInfo.INSTANCE.getServices(); System.out.println("services: " + services.size()); for (Service service : services) { System.out.println("service: " + service + ". total: " + service.getTotalRequestCount()); } Assert.assertEquals(3, services.size()); // try { // Thread.sleep(60000); // } catch (InterruptedException e) { // e.printStackTrace(); // } }
From source file:ufo.remote.calls.benchmark.client.caller.hornetq.HornetQTester.java
@Override protected void startTest(final TesterResult result) { ProducerTemplate producerTemplate = camelContext.createProducerTemplate(); producerTemplate.setExecutorService(Executors.newFixedThreadPool(20)); String url = HornetQApacheCamelConfig.JMS_NAME + ":queue:echo?deliveryPersistent=false&replyToDeliveryPersistent=false"; AtomicInteger failures = new AtomicInteger(0); CountDownLatch latch = new CountDownLatch(result.totalCalls); for (int i = 0; i < result.totalCalls; i++) { producerTemplate.asyncCallbackRequestBody(url, result.message, new Synchronization() { @Override// ww w . j a va2s . c o m public void onFailure(final Exchange exchange) { failures.incrementAndGet(); latch.countDown(); } @Override public void onComplete(final Exchange exchange) { if (logger.isDebugEnabled()) { logger.debug("Received message [{}]", exchange.getIn().getBody()); } latch.countDown(); } }); } try { latch.await(); } catch (InterruptedException e) { throw new RuntimeException(e); } result.failures = failures.get(); }
From source file:ufo.remote.calls.benchmark.client.caller.activemq.ActiveMQTester.java
@Override protected void startTest(final TesterResult result) { ProducerTemplate producerTemplate = camelContext.createProducerTemplate(); producerTemplate.setExecutorService(Executors.newFixedThreadPool(20)); String url = ActiveMQApacheCamelConfig.JMS_NAME + ":queue:echo?deliveryPersistent=false&replyToDeliveryPersistent=false"; AtomicInteger failures = new AtomicInteger(0); CountDownLatch latch = new CountDownLatch(result.totalCalls); for (int i = 0; i < result.totalCalls; i++) { producerTemplate.asyncCallbackRequestBody(url, result.message, new Synchronization() { @Override/* ww w .j av a 2 s .com*/ public void onFailure(final Exchange exchange) { failures.incrementAndGet(); latch.countDown(); } @Override public void onComplete(final Exchange exchange) { if (logger.isDebugEnabled()) { logger.debug("Received message [{}]", exchange.getIn().getBody()); } latch.countDown(); } }); } try { latch.await(); } catch (InterruptedException e) { throw new RuntimeException(e); } result.failures = failures.get(); }
From source file:at.ac.tuwien.dsg.cloud.utilities.messaging.lightweight.rabbitMq.RabbitMqConsumer.java
public RabbitMqConsumer(ReceivingChannel channel) { this.messageListeners = new HashMap<>(); this.threadPool = Executors.newFixedThreadPool(1); this.channel = channel; this.messageFifo = new CircularFifoQueue<>(100); }
From source file:com.flipkart.bifrost.SampleUsageTest.java
@Test public void testSendReceive() throws Exception { ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY); Connection connection = new Connection(Lists.newArrayList("localhost"), "guest", "guest"); connection.start();//from w w w . j a v a 2 s . c o m //Create executor BifrostExecutor<Map<String, Object>> executor = BifrostExecutor .<Map<String, Object>>builder(HttpCallCommand.class).connection(connection).objectMapper(mapper) .requestQueue("bifrost-send").responseQueue("bifrost-recv") .executorService(Executors.newFixedThreadPool(10)).responseWaitTimeout(20000).build(); //Create execution server BifrostRemoteCallExecutionServer<Map<String, Object>> executionServer = BifrostRemoteCallExecutionServer .<Map<String, Object>>builder(HttpCallCommand.class).objectMapper(mapper).connection(connection) .concurrency(10).requestQueue("bifrost-send").build(); executionServer.start(); //Start making calls RemoteCallable<Map<String, Object>> callable = HttpCallCommand.createGet("http://jsonip.com/"); Future<Map<String, Object>> result = executor.submit(callable); Map<String, Object> r = result.get(); //Shutdown exverything when done executor.shutdown(); executionServer.stop(); connection.stop(); Assert.assertTrue(r.containsKey("ip")); }