List of usage examples for java.util.concurrent Executors newFixedThreadPool
public static ExecutorService newFixedThreadPool(int nThreads)
From source file:eu.serco.dhus.plugin.synergy1eo.Synergy1EoPlugin.java
public Synergy1EoPlugin() { executor = Executors.newFixedThreadPool(MAX_THREADS_NUMBER); map = new HashMap<String, String>(); map.put("SY_1_MISR__", "SY_1_2"); map.put("SY_2_SYN___", "SY_1_2"); map.put("SY_2_VGP___", "SY_1_2"); map.put("SY_2_VGK___", "SY_1_2"); map.put("SY_2_VG1___", "SY_2_VG"); map.put("SY_2_V10___", "SY_2_VG"); try {//from w w w . j a va 2 s.c om loadTaskTables(); loadSelectionRulesProperties(); externalDHuSUrl = ConfigurationManager.getExternalDHuSHost(); hashedString = ConfigurationManager.getHashedConnectionString(); } catch (ParserConfigurationException pce) { pce.printStackTrace(); } catch (SAXException saxe) { saxe.printStackTrace(); } catch (IOException ioe) { ioe.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.espertech.esper.multithread.TestMTStmtNamedWindowMerge.java
private void trySend(int numThreads, int numEventsPerThread) throws Exception { Configuration config = SupportConfigFactory.getConfiguration(); config.addEventType("SupportBean", SupportBean.class); engine = EPServiceProviderManager.getDefaultProvider(config); engine.initialize();/* w w w . j av a2 s. com*/ // setup statements engine.getEPAdministrator().createEPL("create window MyWindow.win:keepall() as select * from SupportBean"); engine.getEPAdministrator() .createEPL("on SupportBean sb " + "merge MyWindow nw where nw.theString = sb.theString " + " when not matched then insert select * " + " when matched then update set intPrimitive = nw.intPrimitive + 1"); // execute ExecutorService threadPool = Executors.newFixedThreadPool(numThreads); Future<Boolean> future[] = new Future[numThreads]; for (int i = 0; i < numThreads; i++) { future[i] = threadPool.submit(new StmtNamedWindowMergeCallable(engine, numEventsPerThread)); } threadPool.shutdown(); threadPool.awaitTermination(10, TimeUnit.SECONDS); // total up result for (int i = 0; i < numThreads; i++) { Boolean result = future[i].get(); assertTrue(result); } // compare EventBean[] rows = engine.getEPRuntime().executeQuery("select * from MyWindow").getArray(); assertEquals(numEventsPerThread, rows.length); for (EventBean row : rows) { assertEquals(numThreads - 1, row.get("intPrimitive")); } //long deltaTime = endTime - startTime; //System.out.println("Totals updated: " + totalUpdates + " Delta cumu: " + deltaCumulative + " Delta pooled: " + deltaTime); }
From source file:org.dasein.cloud.utils.requester.DaseinParallelRequestExecutor.java
public List<T> execute() throws DaseinRequestException { final HttpClientBuilder clientBuilder = setProxyIfRequired(httpClientBuilder); final CloseableHttpClient httpClient = clientBuilder.build(); List<T> results = new ArrayList<T>(); List<Callable<T>> tasks = new ArrayList<Callable<T>>(); for (final HttpUriRequest httpUriRequest : httpUriRequests) { tasks.add(new Callable<T>() { @Override/* w ww. j a v a 2s . co m*/ public T call() throws Exception { return execute(httpClient, httpUriRequest); } }); } try { try { ExecutorService executorService = Executors.newFixedThreadPool(httpUriRequests.size()); List<Future<T>> futures = executorService.invokeAll(tasks); for (Future<T> future : futures) { T result = future.get(); results.add(result); } return results; } finally { httpClient.close(); } } catch (Exception e) { throw new DaseinRequestException(e.getMessage(), e); } }
From source file:ch.ledcom.maven.sitespeed.crawler.SiteSpeedCrawlerTest.java
@Before public void setUp() { HttpClient httpClient = new HttpClientProvider(5, 5000, 5000, (String) null, "").get(); HTMLPageResponseFetcher responseFetcher = new HttpClientResponseFetcher(httpClient); ExecutorService service = Executors.newFixedThreadPool(2); Parser parser = new AhrefParser(); Crawler crawler = new DefaultCrawler(responseFetcher, service, parser); ssCrawler = new SiteSpeedCrawler(crawler, 2, true, "/", "", "", HTTP_URL1); }
From source file:edu.illinois.ncsa.versus.engine.impl.ExecutionEngine.java
public ExecutionEngine() { newFixedThreadPool = Executors.newFixedThreadPool(EXECUTION_THREADS); jobs = new ArrayList<Job>(); }
From source file:org.ops4j.orient.spring.tx.blueprints.OrientGraphTransactionTest.java
@Test public void commitMultiThreaded() throws InterruptedException { ExecutorService executorService = Executors.newFixedThreadPool(5); for (int i = 0; i < 5; i++) { executorService.submit(new CommitTask()); }//w w w. j a v a 2 s. c o m executorService.shutdown(); executorService.awaitTermination(1000, TimeUnit.SECONDS); }
From source file:io.undertow.servlet.test.request.ExecutorPerServletTestCase.java
public int runTest(final String path) throws IOException, ExecutionException, InterruptedException { ExecutorService executor = Executors.newFixedThreadPool(NUM_THREADS); try {/*w w w . ja v a2 s. c o m*/ final List<Future<?>> futures = new ArrayList<>(); for (int i = 0; i < NUM_THREADS; ++i) { futures.add(executor.submit(new Runnable() { @Override public void run() { TestHttpClient client = new TestHttpClient(); try { for (int i = 0; i < NUM_REQUESTS; ++i) { HttpGet get = new HttpGet( DefaultServer.getDefaultServerURL() + "/servletContext" + path); HttpResponse result = client.execute(get); Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode()); final String response = HttpClientUtils.readResponse(result); } } catch (IOException e) { throw new RuntimeException(e); } finally { client.getConnectionManager().shutdown(); } } })); } for (Future<?> future : futures) { future.get(); } TestHttpClient client = new TestHttpClient(); try { HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/servletContext" + path); HttpResponse result = client.execute(get); Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode()); return Integer.parseInt(HttpClientUtils.readResponse(result)); } finally { client.getConnectionManager().shutdown(); } } finally { executor.shutdown(); } }
From source file:com.cloudera.knittingboar.sgd.iterativereduce.TestPOLRIterativeReduce.java
@Before public void setUp() throws Exception { masterAddress = new InetSocketAddress(9999); pool = Executors.newFixedThreadPool(4); baseDir = Files.createTempDir(); configuration = new Configuration(); configuration.setInt("com.cloudera.knittingboar.setup.FeatureVectorSize", 10000); configuration.setInt("com.cloudera.knittingboar.setup.numCategories", 20); configuration.setInt("com.cloudera.knittingboar.setup.BatchSize", 200); configuration.setInt("com.cloudera.knittingboar.setup.NumberPasses", 1); // local input split path configuration.set("com.cloudera.knittingboar.setup.LocalInputSplitPath", "hdfs://127.0.0.1/input/0"); // setup 20newsgroups configuration.set("com.cloudera.knittingboar.setup.RecordFactoryClassname", "com.cloudera.knittingboar.records.TwentyNewsgroupsRecordFactory"); workerServices = new ArrayList<ApplicationWorkerService<ParameterVectorGradientUpdatable>>(); workers = new ArrayList<Future<Integer>>(); computableWorkers = new ArrayList<ComputableWorker<ParameterVectorGradientUpdatable>>(); setUpMaster();//from w w w . j av a2 s . com setUpWorker("worker1"); setUpWorker("worker2"); setUpWorker("worker3"); }
From source file:com.alibaba.dubbo.demo.consumer.DemoAction.java
public void start() throws Exception { int threads = 100; final DescriptiveStatistics stats = new SynchronizedDescriptiveStatistics(); DubboBenchmark.BenchmarkMessage msg = prepareArgs(); final byte[] msgBytes = msg.toByteArray(); int n = 1000000; final CountDownLatch latch = new CountDownLatch(n); ExecutorService es = Executors.newFixedThreadPool(threads); final AtomicInteger trans = new AtomicInteger(0); final AtomicInteger transOK = new AtomicInteger(0); long start = System.currentTimeMillis(); for (int i = 0; i < n; i++) { es.submit(() -> {// ww w. j a va 2 s . c o m try { long t = System.currentTimeMillis(); DubboBenchmark.BenchmarkMessage m = testSay(msgBytes); t = System.currentTimeMillis() - t; stats.addValue(t); trans.incrementAndGet(); if (m != null && m.getField1().equals("OK")) { transOK.incrementAndGet(); } } catch (InterruptedException e) { e.printStackTrace(); } finally { latch.countDown(); } }); } latch.await(); start = System.currentTimeMillis() - start; System.out.printf("sent requests : %d\n", n); System.out.printf("received requests : %d\n", trans.get()); System.out.printf("received requests_OK : %d\n", transOK.get()); System.out.printf("throughput (TPS) : %d\n", n * 1000 / start); System.out.printf("mean: %f\n", stats.getMean()); System.out.printf("median: %f\n", stats.getPercentile(50)); System.out.printf("max: %f\n", stats.getMax()); System.out.printf("min: %f\n", stats.getMin()); System.out.printf("99P: %f\n", stats.getPercentile(90)); }
From source file:org.freewheelschedule.freewheel.remoteworker.RunnerThread.java
private void createThreadPool() { threadPool = Executors.newFixedThreadPool(numberOfThreads); }