Task:Excutor 와 @Async
@Service
public class ModuleProposeBoxMailService{
@Autowired
private JavaMailSender mailSender;
@Autowired
private TaskExecutor taskExecutor;
public void sendMail(Map<String, Object> paramMap) {
taskExecutor.execute(new Task(paramMap));
}
private class Task implements Runnable {
private Map<String, Object> paramMap;
public Task(Map<String, Object> paramMap) {
this.paramMap = paramMap;
}
public void run() {
boolean isSend=false;
try {
MimeMessage message = mailSender.createMimeMessage();
MimeMessageHelper helper;
File attachFile = null;
if(paramMap.get("attachFile")!=null&&!((String)paramMap.get("attachFile")).equals("")){
attachFile = new File(PineTree.getSiteContext().getRealPath((String)paramMap.get("attachFile")));
helper = new MimeMessageHelper(message, true , "UTF-8");
}else{
helper = new MimeMessageHelper(message, "UTF-8");
}
String from = (String)paramMap.get("receivedMail");
String[] to = (String[])paramMap.get("senderMail");
String subject = (String)paramMap.get("proposeTitle");
String body = (String)paramMap.get("proposeContent");
helper.setTo(to);
helper.setFrom(from);
helper.setSubject(subject);
helper.setText(body, true);
if(attachFile!=null){
DataSource dataSource = new FileDataSource(attachFile);
helper.addAttachment(MimeUtility.encodeText(attachFile.getName()), dataSource);
}
mailSender.send(message);
isSend = true;
} catch (MessagingException e) {
throw new MailPreparationException(e);
} catch (UnsupportedEncodingException e) {
throw new SystemRuntimeException(e);
}
}
}
}
위와 같이 runable 을 사용할 경우 잘된다.... 긍데...
다음과 같이 Async를 사용하면 꿀먹은 벙어리 처럼 ...디버깅 해보면 잘 타는데 ...작동하지 않는다.
@Service
public class ModuleProposeBoxMailService {
@Autowired
private JavaMailSender mailSender;
@Async
public Future<Boolean> sendMail(Map<String, Object> paramMap) {
boolean isSend=false;
try {
MimeMessage message = mailSender.createMimeMessage();
MimeMessageHelper helper;
File attachFile = null;
if(paramMap.get("attachFile")!=null&&!((String)paramMap.get("attachFile")).equals("")){
attachFile = new File(PineTree.getSiteContext().getRealPath((String)paramMap.get("attachFile")));
helper = new MimeMessageHelper(message, true , "UTF-8");
}else{
helper = new MimeMessageHelper(message, "UTF-8");
}
String from = (String)paramMap.get("receivedMail");
String[] to = (String[])paramMap.get("senderMail");
String subject = (String)paramMap.get("proposeTitle");
String body = (String)paramMap.get("proposeContent");
helper.setTo(to);
helper.setFrom(from);
helper.setSubject(subject);
helper.setText(body, true);
if(attachFile!=null){
DataSource dataSource = new FileDataSource(attachFile);
helper.addAttachment(MimeUtility.encodeText(attachFile.getName()), dataSource);
}
mailSender.send(message);
isSend = true;
} catch (MessagingException e) {
throw new MailPreparationException(e);
} catch (UnsupportedEncodingException e) {
throw new SystemRuntimeException(e);
}
return new AsyncResult<Boolean>(isSend);
}
}
이유를 보면.. 시간없어서 미루다가 오늘중에 찾아볼예정
public class ModuleProposeBoxMailService{
@Autowired
private JavaMailSender mailSender;
@Autowired
private TaskExecutor taskExecutor;
public void sendMail(Map<String, Object> paramMap) {
taskExecutor.execute(new Task(paramMap));
}
private class Task implements Runnable {
private Map<String, Object> paramMap;
public Task(Map<String, Object> paramMap) {
this.paramMap = paramMap;
}
public void run() {
boolean isSend=false;
try {
MimeMessage message = mailSender.createMimeMessage();
MimeMessageHelper helper;
File attachFile = null;
if(paramMap.get("attachFile")!=null&&!((String)paramMap.get("attachFile")).equals("")){
attachFile = new File(PineTree.getSiteContext().getRealPath((String)paramMap.get("attachFile")));
helper = new MimeMessageHelper(message, true , "UTF-8");
}else{
helper = new MimeMessageHelper(message, "UTF-8");
}
String from = (String)paramMap.get("receivedMail");
String[] to = (String[])paramMap.get("senderMail");
String subject = (String)paramMap.get("proposeTitle");
String body = (String)paramMap.get("proposeContent");
helper.setTo(to);
helper.setFrom(from);
helper.setSubject(subject);
helper.setText(body, true);
if(attachFile!=null){
DataSource dataSource = new FileDataSource(attachFile);
helper.addAttachment(MimeUtility.encodeText(attachFile.getName()), dataSource);
}
mailSender.send(message);
isSend = true;
} catch (MessagingException e) {
throw new MailPreparationException(e);
} catch (UnsupportedEncodingException e) {
throw new SystemRuntimeException(e);
}
}
}
}
위와 같이 runable 을 사용할 경우 잘된다.... 긍데...
다음과 같이 Async를 사용하면 꿀먹은 벙어리 처럼 ...디버깅 해보면 잘 타는데 ...작동하지 않는다.
@Service
public class ModuleProposeBoxMailService {
@Autowired
private JavaMailSender mailSender;
@Async
public Future<Boolean> sendMail(Map<String, Object> paramMap) {
boolean isSend=false;
try {
MimeMessage message = mailSender.createMimeMessage();
MimeMessageHelper helper;
File attachFile = null;
if(paramMap.get("attachFile")!=null&&!((String)paramMap.get("attachFile")).equals("")){
attachFile = new File(PineTree.getSiteContext().getRealPath((String)paramMap.get("attachFile")));
helper = new MimeMessageHelper(message, true , "UTF-8");
}else{
helper = new MimeMessageHelper(message, "UTF-8");
}
String from = (String)paramMap.get("receivedMail");
String[] to = (String[])paramMap.get("senderMail");
String subject = (String)paramMap.get("proposeTitle");
String body = (String)paramMap.get("proposeContent");
helper.setTo(to);
helper.setFrom(from);
helper.setSubject(subject);
helper.setText(body, true);
if(attachFile!=null){
DataSource dataSource = new FileDataSource(attachFile);
helper.addAttachment(MimeUtility.encodeText(attachFile.getName()), dataSource);
}
mailSender.send(message);
isSend = true;
} catch (MessagingException e) {
throw new MailPreparationException(e);
} catch (UnsupportedEncodingException e) {
throw new SystemRuntimeException(e);
}
return new AsyncResult<Boolean>(isSend);
}
}
이유를 보면.. 시간없어서 미루다가 오늘중에 찾아볼예정
댓글
댓글 쓰기