public void testConcurrentPipeline() throws Exception { int total = 200; final int group = total / 20; MockEndpoint mock = getMockEndpoint("mock:result"); mock.expectedMessageCount(total); ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setCorePoolSize(20); executor.afterPropertiesSet(); for (int i = 0; i < 20; i++) { final int threadCount = i; executor.execute( new Runnable() { public void run() { int start = threadCount * group; for (int i = 0; i < group; 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, "" + (start + i)); } } }); } mock.assertIsSatisfied(); mock.expectsNoDuplicates(body()); executor.shutdown(); }
@Override public void onApplicationEvent(ApplicationEvent event) { if (event instanceof ContextRefreshedEvent) { taskExecutor = new ThreadPoolTaskExecutor(); taskExecutor.setMaxPoolSize(100); taskExecutor.initialize(); } else if (event instanceof ContextClosedEvent) { taskExecutor.shutdown(); } }
public void onApplicationEvent(ContextClosedEvent event) { System.out.println("==================Spring Context is shutting down=============="); scheduler.shutdown(); executor.shutdown(); }