public static void main(String[] args) throws MalformedURLException { ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml"); /* UserService userService = (UserService) context.getBean("userService"); User user = new User(); user.setAge(25); user.setName("gaohuan"); userService.save(user); */ UserBusiness userBusiness = context.getBean(UserBusiness.class); ThreadPoolTaskExecutor poolTaskExecutor = new ThreadPoolTaskExecutor(); // 线程池所使用的缓冲队列 poolTaskExecutor.setQueueCapacity(200); // 线程池维护线程的最少数量 poolTaskExecutor.setCorePoolSize(10); // 线程池维护线程的最大数量 poolTaskExecutor.setMaxPoolSize(1000); // 线程池维护线程所允许的空闲时间 poolTaskExecutor.setKeepAliveSeconds(30000); poolTaskExecutor.initialize(); // 测试1 for (int i = 0; i < 10; i++) { poolTaskExecutor.execute( new Runnable() { @Override public void run() { for (int j = 0; j < 10; j++) { User user = new User("高欢-" + j, 25); BusinessResult<String> result = userBusiness.signIn(user); } } }); } for (int i = 0; i < 10; i++) { poolTaskExecutor.execute( new Runnable() { @Override public void run() { for (int j = 0; j < 2; j++) { userBusiness.signIn(null); } } }); } System.out.println("-------------运行成功---------------"); // System.exit(1); }
@Bean(name = "rabbitCleanupThreadPool") public ThreadPoolTaskExecutor rabbitCleanupThreadPool() { ThreadPoolTaskExecutor t = new ThreadPoolTaskExecutor(); t.setCorePoolSize(2); t.setMaxPoolSize(3); t.setQueueCapacity(3); t.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); return t; }
@Override @Bean(name = "taskExecutor") public Executor getAsyncExecutor() { log.debug("Creating Async Task Executor"); ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setCorePoolSize(jHipsterProperties.getAsync().getCorePoolSize()); executor.setMaxPoolSize(jHipsterProperties.getAsync().getMaxPoolSize()); executor.setQueueCapacity(jHipsterProperties.getAsync().getQueueCapacity()); executor.setThreadNamePrefix("nailit-Executor-"); return new ExceptionHandlingAsyncTaskExecutor(executor); }
@Override @Bean public Executor getAsyncExecutor() { log.debug("Creating Async Task Executor"); ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setCorePoolSize(propertyResolver.getProperty("corePoolSize", Integer.class, 2)); executor.setMaxPoolSize(propertyResolver.getProperty("maxPoolSize", Integer.class, 50)); executor.setQueueCapacity(propertyResolver.getProperty("queueCapacity", Integer.class, 10000)); executor.setThreadNamePrefix("milkyway-Executor-"); return new ExceptionHandlingAsyncTaskExecutor(executor); }
@Override @Bean(name = "taskExecutor") public Executor getAsyncExecutor() { log.debug("Creating Async Task Executor"); ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setCorePoolSize(applicationProperties.getAsync().getCorePoolSize()); executor.setMaxPoolSize(applicationProperties.getAsync().getMaxPoolSize()); executor.setQueueCapacity(applicationProperties.getAsync().getQueueCapacity()); executor.setThreadNamePrefix("ppwebtv-Executor-"); return ExceptionHandlingAsyncTaskExecutor.of(executor); }
@Override public Executor getAsyncExecutor() { logger.debug("Enter: getAsynchExecutor"); ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setCorePoolSize(7); executor.setMaxPoolSize(42); executor.setQueueCapacity(11); executor.setThreadNamePrefix("AsyncExecutor-"); executor.initialize(); logger.debug("Exit: getAsynchExecutor"); return executor; }
@Bean public ThreadPoolTaskExecutor taskExecutor() { ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setCorePoolSize(4); executor.setMaxPoolSize(4); executor.setQueueCapacity(1000); executor.setThreadNamePrefix("ReporterExecutor-"); executor.initialize(); return executor; }