`

Spring 线程池使用2

阅读更多

<!-- 配置异步线程执行器 -->  <!-- 为异步线程执行器 进注入  -->

<bean id="taskExecutor"

class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">

<!-- 设置核心池子的大小 -->

<property name="corePoolSize" value="10"></property>

<!-- 设置最大池子的大小  --> 

<property name="maxPoolSize" value="30"></property>

</bean>

 

 

public void sendFindPasswordMail(final UserT user,final String password) throws MessagingException, IOException, TemplateException {

 

this.getTaskExecutor().execute(new Runnable() {

       String emailcontent = " 尊敬的会员  " + user.getUsername() +" 您好,您的重置密码是 "+ password;

 public void run() { 

InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("email.properties");

Properties p = new Properties();

try {

p.load(inputStream);

} catch (IOException e1) {

e1.printStackTrace();

}

ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");

JavaMailSender sender = (JavaMailSender) ctx.getBean("javamailsenderimpl");

MimeMessage msg = sender.createMimeMessage();

MimeMessageHelper helper = null;

try {

helper = new MimeMessageHelper(msg, false, "UTF-8");

} catch (MessagingException e1) {

e1.printStackTrace();

}

try {

helper.setTo(user.getEmail());

helper.setFrom(p.getProperty("email.username"));

helper.setSubject("中付通会员找回密码邮件");

helper.setText("", true);

} catch (MessagingException e) {

e.printStackTrace();

}

sender.send(msg);

 

}

});

 

}

 

private TaskExecutor taskExecutor;

 

 

@JSON(serialize = false)

public TaskExecutor getTaskExecutor() {

return taskExecutor;

}

 

public void setTaskExecutor(TaskExecutor taskExecutor) {

this.taskExecutor = taskExecutor;

}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics