springboot多线程实现邮件发送

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(); } } });

  

转载于:https://www.cnblogs.com/person008/p/11463298.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值