List of usage examples for java.util.concurrent ExecutorService shutdown
void shutdown();
From source file:com.espertech.esper.multithread.TestMTStmtNamedWindowSubqueryLookup.java
private void trySend(int numThreads, int numEventsPerThread) throws Exception { Configuration config = SupportConfigFactory.getConfiguration(); config.getEngineDefaults().getEventMeta() .setDefaultEventRepresentation(Configuration.EventRepresentation.MAP); // use Map-type events for testing config.addEventType("SupportBean", SupportBean.class); engine = EPServiceProviderManager.getDefaultProvider(config); engine.initialize();//from w w w . ja v a2s . co m // setup statements engine.getEPAdministrator().createEPL("create schema MyUpdateEvent as (key string, intupd int)"); engine.getEPAdministrator().createEPL("create schema MySchema as (theString string, intval int)"); EPStatement namedWindow = engine.getEPAdministrator() .createEPL("create window MyWindow.win:keepall() as MySchema"); engine.getEPAdministrator() .createEPL("on MyUpdateEvent mue merge MyWindow mw " + "where mw.theString = mue.key " + "when not matched then insert select key as theString, intupd as intval " + "when matched then delete"); EPStatement targetStatement = engine.getEPAdministrator().createEPL( "select (select intval from MyWindow mw where mw.theString = sb.theString) as val from SupportBean sb"); // execute ExecutorService threadPool = Executors.newFixedThreadPool(numThreads); Future<Boolean> future[] = new Future[numThreads]; for (int i = 0; i < numThreads; i++) { future[i] = threadPool.submit( new StmtNamedWindowSubqueryLookupCallable(i, engine, numEventsPerThread, targetStatement)); } threadPool.shutdown(); threadPool.awaitTermination(10, TimeUnit.SECONDS); // total up result for (int i = 0; i < numThreads; i++) { Boolean result = future[i].get(); assertTrue(result); } EventBean[] events = EPAssertionUtil.iteratorToArray(namedWindow.iterator()); assertEquals(0, events.length); }
From source file:it.infn.ct.futuregateway.apiserver.APIContextListener.java
@Override public final void contextDestroyed(final ServletContextEvent sce) { ExecutorService exServ; try {/*w w w.j a v a 2s . c o m*/ Context ctx = new InitialContext(); exServ = (ExecutorService) ctx.lookup("java:comp/env/threads/Submitter"); } catch (NamingException ex) { exServ = (ExecutorService) sce.getServletContext().getAttribute("SubmissionThreadPool"); } exServ.shutdown(); try { if (!exServ.awaitTermination(Constants.MAXTHREADWAIT, TimeUnit.MINUTES)) { log.warn("Failed to shutdown the submission thread pool."); } } catch (InterruptedException ex) { log.error(ex); } }
From source file:com.espertech.esper.multithread.TestMTStmtNamedWindowSubqueryAgg.java
private void trySend(int numThreads, int numEventsPerThread, boolean indexShare) throws Exception { Configuration config = SupportConfigFactory.getConfiguration(); config.addEventType("SupportBean", SupportBean.class); config.addPlugInAggregationFunction("intListAgg", MyIntListAggregation.class.getName()); config.getEngineDefaults().getEventMeta() .setDefaultEventRepresentation(Configuration.EventRepresentation.MAP); // use Map-type events for testing engine = EPServiceProviderManager.getDefaultProvider(config); engine.initialize();//www. j a v a2 s. com // setup statements engine.getEPAdministrator().createEPL("create schema UpdateEvent as (uekey string, ueint int)"); engine.getEPAdministrator().createEPL("create schema WindowSchema as (wskey string, wsint int)"); String createEpl = "create window MyWindow.win:keepall() as WindowSchema"; if (indexShare) { createEpl = "@Hint('enable_window_subquery_indexshare') " + createEpl; } EPStatement namedWindow = engine.getEPAdministrator().createEPL(createEpl); engine.getEPAdministrator().createEPL("create index ABC on MyWindow(wskey)"); engine.getEPAdministrator() .createEPL("on UpdateEvent mue merge MyWindow mw " + "where uekey = wskey and ueint = wsint " + "when not matched then insert select uekey as wskey, ueint as wsint " + "when matched then delete"); // note: here all threads use the same string key to insert/delete and different values for the int EPStatement targetStatement = engine.getEPAdministrator().createEPL( "select (select intListAgg(wsint) from MyWindow mw where wskey = sb.theString) as val from SupportBean sb"); // execute ExecutorService threadPool = Executors.newFixedThreadPool(numThreads); Future<Boolean> future[] = new Future[numThreads]; for (int i = 0; i < numThreads; i++) { future[i] = threadPool .submit(new StmtNamedWindowSubqueryAggCallable(i, engine, numEventsPerThread, targetStatement)); } threadPool.shutdown(); threadPool.awaitTermination(10, TimeUnit.SECONDS); // total up result for (int i = 0; i < numThreads; i++) { Boolean result = future[i].get(); assertTrue(result); } EventBean[] events = EPAssertionUtil.iteratorToArray(namedWindow.iterator()); assertEquals(0, events.length); }
From source file:com.ras.updater.Downloader.java
/** * This method will check for updates on all {@link #m_fileProviders} and download anything with an update. * @return true if at least one file was updated or false if no files were updated */// w w w. j a v a 2 s . c o m public boolean update() { ArrayList<Future<Boolean>> results = new ArrayList<Future<Boolean>>(); ExecutorService es = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); for (IFileProvider fileProvider : m_fileProviders) { FileUpdaterCallable task = new FileUpdaterCallable(fileProvider); results.add(es.submit(task)); } es.shutdown(); try { if (!es.awaitTermination(m_downloadTimeout, m_downloadTimeUnit)) es.shutdownNow(); } catch (InterruptedException e) { m_statusCallback.handleError(e); es.shutdownNow(); Thread.currentThread().interrupt(); } //Loop through the results for update values for (Future<Boolean> result : results) { try { if (result.isDone() && result.get() != null && result.get()) return true; } catch (InterruptedException e) { //This should never happen m_statusCallback.handleError(e); } catch (ExecutionException e) { m_statusCallback.handleError(e); } } return false; }
From source file:net.openhft.chronicle.logger.log4j1.Log4j1IndexedChroniclePerfTest.java
@Test public void testMultiThreadLogging() throws IOException, InterruptedException { warmup(LoggerFactory.getLogger("perf-binary-indexed-chronicle")); warmup(LoggerFactory.getLogger("perf-plain-indexed")); final int RUNS = 1000000; final int THREADS = 10; for (int size : new int[] { 64, 128, 256 }) { {/*from ww w .j a va 2 s. c o m*/ final long start = System.nanoTime(); ExecutorService es = Executors.newFixedThreadPool(THREADS); for (int t = 0; t < THREADS; t++) { es.submit(new RunnableLogger(RUNS, size, "perf-binary-indexed-chronicle")); } es.shutdown(); es.awaitTermination(60, TimeUnit.SECONDS); final long time = System.nanoTime() - start; System.out.printf( "ChronicleLog.MT (runs=%d, min size=%03d, elapsed=%.3f ms) took an average of %.3f us per entry\n", RUNS, size, time / 1e6, time / 1e3 / (RUNS * THREADS)); } { final long start = System.nanoTime(); ExecutorService es = Executors.newFixedThreadPool(THREADS); for (int t = 0; t < THREADS; t++) { es.submit(new RunnableLogger(RUNS, size, "perf-plain-indexed")); } es.shutdown(); es.awaitTermination(60, TimeUnit.SECONDS); final long time = System.nanoTime() - start; System.out.printf( "Plain.MT (runs=%d, min size=%03d, elapsed=%.3f ms)): took an average of %.3f us per entry\n", RUNS, size, time / 1e6, time / 1e3 / (RUNS * THREADS)); } } ChronicleTools.deleteOnExit(basePath("perf-binary-indexed-chronicle")); }
From source file:net.openhft.chronicle.logger.log4j1.Log4j1VanillaChroniclePerfTest.java
@Test public void testMultiThreadLogging() throws IOException, InterruptedException { warmup(LoggerFactory.getLogger("perf-binary-vanilla-chronicle")); warmup(LoggerFactory.getLogger("perf-plain-vanilla")); final int RUNS = 100000; // ~ 10s final int THREADS = Runtime.getRuntime().availableProcessors(); for (int size : new int[] { 64, 128, 256 }) { {// w w w . ja v a2s . c o m final long start = System.nanoTime(); ExecutorService es = Executors.newFixedThreadPool(THREADS); for (int t = 0; t < THREADS; t++) { es.submit(new RunnableLogger(RUNS, size, "perf-binary-vanilla-chronicle")); } es.shutdown(); es.awaitTermination(2, TimeUnit.MINUTES); final long time = System.nanoTime() - start; System.out.printf( "ChronicleLog.MT (runs=%d, min size=%03d, elapsed=%.3f ms) took an average of %.3f us per entry\n", RUNS, size, time / 1e6, time / 1e3 / (RUNS * THREADS)); } { final long start = System.nanoTime(); ExecutorService es = Executors.newFixedThreadPool(THREADS); for (int t = 0; t < THREADS; t++) { es.submit(new RunnableLogger(RUNS, size, "perf-plain-vanilla")); } es.shutdown(); es.awaitTermination(5, TimeUnit.MINUTES); final long time = System.nanoTime() - start; System.out.printf( "Plain.MT (runs=%d, min size=%03d, elapsed=%.3f ms)): took an average of %.3f us per entry\n", RUNS, size, time / 1e6, time / 1e3 / (RUNS * THREADS)); } } IOTools.deleteDir(basePath("perf-binary-vanilla-chronicle")); }
From source file:net.openhft.chronicle.logger.logback.LogbackVanillaChroniclePerfTest.java
@Test public void testMultiThreadLogging() throws IOException, InterruptedException { warmup(LoggerFactory.getLogger("perf-binary-vanilla-chronicle")); warmup(LoggerFactory.getLogger("perf-plain-vanilla")); final int THREADS = Runtime.getRuntime().availableProcessors(); for (int size : new int[] { 64, 128, 256 }) { {/*from ww w. j ava 2 s .c om*/ final int RUNS = 250000; final long start = System.nanoTime(); ExecutorService es = Executors.newFixedThreadPool(THREADS); for (int t = 0; t < THREADS; t++) { es.submit(new RunnableLogger(RUNS, size, "perf-binary-vanilla-chronicle")); } es.shutdown(); es.awaitTermination(2, TimeUnit.MINUTES); final long time = System.nanoTime() - start; System.out.printf( "ChronicleLog.MT (runs=%d, min size=%03d, elapsed=%.3f ms) took an average of %.3f us per entry\n", RUNS, size, time / 1e6, time / 1e3 / (RUNS * THREADS)); } { final int RUNS = 10000; final long start = System.nanoTime(); ExecutorService es = Executors.newFixedThreadPool(THREADS); for (int t = 0; t < THREADS; t++) { es.submit(new RunnableLogger(RUNS, size, "perf-plain-vanilla")); } es.shutdown(); es.awaitTermination(5, TimeUnit.MINUTES); final long time = System.nanoTime() - start; System.out.printf( "Plain.MT (runs=%d, min size=%03d, elapsed=%.3f ms)): took an average of %.3f us per entry\n", RUNS, size, time / 1e6, time / 1e3 / (RUNS * THREADS)); } } IOTools.deleteDir(basePath("perf-binary-vanilla-chronicle")); }
From source file:net.openhft.chronicle.logger.log4j2.Log4j2VanillaChroniclePerfTest.java
@Test public void testMultiThreadLogging() throws IOException, InterruptedException { warmup(LoggerFactory.getLogger("perf-binary-vanilla-chronicle")); warmup(LoggerFactory.getLogger("perf-plain-vanilla")); final int RUNS = 250000; // ~10s final int THREADS = Runtime.getRuntime().availableProcessors(); for (int size : new int[] { 64, 128, 256 }) { {/*w w w . j a v a 2 s .c o m*/ final long start = System.nanoTime(); ExecutorService es = Executors.newFixedThreadPool(THREADS); for (int t = 0; t < THREADS; t++) { es.submit(new RunnableLogger(RUNS, size, "perf-binary-vanilla-chronicle")); } es.shutdown(); es.awaitTermination(2, TimeUnit.MINUTES); final long time = System.nanoTime() - start; System.out.printf( "ChronicleLog.MT (runs=%d, min size=%03d, elapsed=%.3f ms) took an average of %.3f us per entry\n", RUNS, size, time / 1e6, time / 1e3 / (RUNS * THREADS)); } { final long start = System.nanoTime(); ExecutorService es = Executors.newFixedThreadPool(THREADS); for (int t = 0; t < THREADS; t++) { es.submit(new RunnableLogger(RUNS, size, "perf-plain-vanilla")); } es.shutdown(); es.awaitTermination(10, TimeUnit.MINUTES); final long time = System.nanoTime() - start; System.out.printf( "Plain.MT (runs=%d, min size=%03d, elapsed=%.3f ms)): took an average of %.3f us per entry\n", RUNS, size, time / 1e6, time / 1e3 / (RUNS * THREADS)); } } IOTools.deleteDir(basePath("perf-binary-vanilla-chronicle")); }
From source file:com.espertech.esper.multithread.TestMTStmtSharedView.java
private void trySend(int numThreads, int numRepeats, int numStatements) throws Exception { // Create same statement X times EPStatement stmt[] = new EPStatement[numStatements]; SupportMTUpdateListener listeners[] = new SupportMTUpdateListener[stmt.length]; for (int i = 0; i < stmt.length; i++) { stmt[i] = engine.getEPAdministrator().createEPL(" select * " + " from " + SupportMarketDataBean.class.getName() + ".std:groupwin(symbol).stat:uni(price)"); listeners[i] = new SupportMTUpdateListener(); stmt[i].addListener(listeners[i]); }/* ww w. j a v a2s .co m*/ // Start send threads // Each threads sends each symbol with price = 0 to numRepeats long startTime = System.currentTimeMillis(); ExecutorService threadPool = Executors.newFixedThreadPool(numThreads); Future future[] = new Future[numThreads]; for (int i = 0; i < numThreads; i++) { Callable callable = new StmtSharedViewCallable(numRepeats, engine, SYMBOLS); future[i] = threadPool.submit(callable); } // Shut down threadPool.shutdown(); threadPool.awaitTermination(10, TimeUnit.SECONDS); for (int i = 0; i < numThreads; i++) { assertTrue((Boolean) future[i].get()); } long endTime = System.currentTimeMillis(); long delta = endTime - startTime; assertTrue("delta=" + delta + " not less then 5 sec", delta < 5000); // should take less then 5 seconds even for 100 statements as they need to share resources thread-safely // Assert results for (SupportMTUpdateListener listener : listeners) { assertEquals(numRepeats * numThreads * SYMBOLS.length, listener.getNewDataList().size()); EventBean[] newDataLast = listener.getNewDataList().get(listener.getNewDataList().size() - 1); assertEquals(1, newDataLast.length); EventBean result = newDataLast[0]; assertEquals(numRepeats * numThreads, ((Long) result.get("datapoints")).longValue()); assertTrue(Arrays.asList(SYMBOLS).contains(result.get("symbol"))); assertEquals(sumToN(numRepeats) * numThreads, result.get("total")); listener.reset(); } for (int i = 0; i < stmt.length; i++) { stmt[i].stop(); } }
From source file:microsoft.exchange.webservices.data.HttpClientWebRequest.java
/** * Releases the connection by Closing./*from w w w . j a va 2 s .c o m*/ */ @Override public void close() { ExecutorService es = CallableSingleTon.getExecutor(); es.shutdown(); if (null != httpPostReq) { httpPostReq.releaseConnection(); //postMethod.abort(); } httpPostReq = null; }