List of usage examples for org.springframework.scheduling.concurrent ThreadPoolTaskExecutor shutdown
public void shutdown()
From source file:com.impetus.ankush.common.controller.listener.StartupListener.java
/** * Shutdown servlet context (currently a no-op method). * /*from w w w.j a v a 2 s. c o m*/ * @param servletContextEvent * The servlet context event */ @Override public void contextDestroyed(final ServletContextEvent servletContextEvent) { try { if (applicationContext != null) { ThreadPoolTaskExecutor pooledExecutor = (ThreadPoolTaskExecutor) applicationContext .getBean("pooledExecutor"); log.debug("Status of pooledExec daemon " + pooledExecutor.isDaemon()); pooledExecutor.shutdown(); ThreadPoolTaskScheduler pooledScheduler = (ThreadPoolTaskScheduler) applicationContext .getBean("pooledScheduler"); log.debug("Status of pooledScheduler daemon " + pooledScheduler.isDaemon()); pooledScheduler.shutdown(); AsyncExecutorServiceImpl executor = (AsyncExecutorServiceImpl) applicationContext .getBean("asyncExecutorService"); executor.shutdown(); } AppStore.destroyStore(); applicationContext = null; } catch (Exception e) { log.error(e.getMessage(), e); } }
From source file:org.apache.camel.component.xquery.XQueryConcurrencyTest.java
@Test public void testConcurrency() throws Exception { int total = 1000; MockEndpoint mock = getMockEndpoint("mock:result"); mock.expectedMessageCount(total);/*w w w . ja va2 s .com*/ // setup a task executor to be able send the messages in parallel ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setCorePoolSize(5); executor.afterPropertiesSet(); for (int i = 0; i < 5; i++) { final int threadCount = i; executor.execute(new Runnable() { public void run() { int start = threadCount * 200; for (int i = 0; i < 200; i++) { try { // do some random sleep to simulate spread in user activity Thread.sleep(new Random().nextInt(10)); } catch (InterruptedException e) { // ignore } template.sendBody(uri, "<person><id>" + (start + i + 1) + "</id><name>James</name></person>"); } } }); } mock.assertNoDuplicates(body()); assertMockEndpointsSatisfied(); executor.shutdown(); }
From source file:com.ethlo.geodata.GeodataServiceImpl.java
public void load() { ensureBaseDirectory();//from w ww . j a va 2 s .c o m final SourceDataInfoSet sourceInfo = geoMetaService.getSourceDataInfo(); if (sourceInfo.isEmpty()) { logger.error( "Cannot start geodata server as there is no data. Please run with 'update' parameter to import data"); System.exit(1); } loadHierarchy(); final ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor(); taskExecutor.setCorePoolSize(3); taskExecutor.setThreadNamePrefix("data-loading-"); taskExecutor.initialize(); taskExecutor.execute(this::loadLocations); taskExecutor.execute(this::loadMbr); taskExecutor.execute(this::loadIps); taskExecutor.setAwaitTerminationSeconds(Integer.MAX_VALUE); taskExecutor.setWaitForTasksToCompleteOnShutdown(true); taskExecutor.shutdown(); //final ResultSet<GeoLocation> result = geoNamesRepository.retrieve(QueryFactory.equal(CqGeonamesRepository.ATTRIBUTE_FEATURE_CODE, "ADM1")); //result.forEach(this::connectAdm1WithCountry); publisher.publishEvent(new DataLoadedEvent(this, DataType.ALL, Operation.LOAD, 1, 1)); }
From source file:org.apache.camel.component.xquery.XQueryURLBasedConcurrencyTest.java
@Test public void testConcurrency() throws Exception { int total = 1000; MockEndpoint mock = getMockEndpoint("mock:result"); mock.expectedMessageCount(total);/*from w w w.j a v a 2 s . co m*/ // setup a task executor to be able send the messages in parallel ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setCorePoolSize(5); executor.afterPropertiesSet(); for (int i = 0; i < 5; i++) { final int threadCount = i; executor.execute(new Runnable() { public void run() { int start = threadCount * 200; for (int i = 0; i < 200; i++) { try { // do some random sleep to simulate spread in user activity Thread.sleep(new Random().nextInt(10)); } catch (InterruptedException e) { // ignore } template.sendBody("direct:start", "<mail><subject>" + (start + i) + "</subject><body>Hello world!</body></mail>"); } } }); } mock.assertIsSatisfied(); // must use bodyAs(String.class) to force DOM to be converted to String XML // for duplication detection mock.assertNoDuplicates(bodyAs(String.class)); executor.shutdown(); }