https://blog.csdn.net/github_39936816/article/details/80557977
https://blog.csdn.net/lu_wei_wei/article/details/80242831
@Configuration public class ThreadPoolConfig {
//这些值也在配置文件配置 // 核心线程池大小 private int corePoolSize = 50; // 最大可创建的线程数 private int maxPoolSize = 200; // 队列最大长度 private int queueCapacity = 1000; // 线程池维护线程所允许的空闲时间 private int keepAliveSeconds = 300; @Bean(name = "threadPoolTaskExecutor") public ThreadPoolTaskExecutor threadPoolTaskExecutor() { ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setMaxPoolSize(maxPoolSize); executor.setCorePoolSize(corePoolSize); executor.setQueueCapacity(queueCapacity); executor.setKeepAliveSeconds(keepAliveSeconds); // 线程池对拒绝任务(无线程可用)的处理策略 executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); return executor; } }
调用
@Autowired
private ThreadPoolConfig threadPoolConfig;
方法中调用----->
threadPoolConfig.threadPoolTaskExecutor().execute(new Runnable() { @Override public void run() { try { String password = String.valueOf((int) ((Math.random() * 9 + 1) * 100000)); user.setSalt(ShiroUtils.randomSalt()); user.setPassword(passwordService.encryptPassword(loginName, password, user.getSalt())); if (userService.resetUserPwd(user) > 0) { String content = "********"; mailService.sendHtmlMail(user.getEmail(), "您的登录密码已经修改!", content); } } catch (Exception e) { System.out.println("邮件发送异常"); e.printStackTrace(); } } });