我有一种用于发送电子邮件的方法。我想锁定这个方法,这样每次只有一个线程可以访问它,其余的同时池化。我应该同步方法还是使用 spring @transactional PROPAGATION_REQUIRED ?
在我的服务层
//each time use new thread to send out email
public void sendThroughSMTP(List<String> emails,String subject,String content){
//each time will open and sent through port 25. dont u think this will caused too many threads spawned?
BlastEmailThread blastEmailThread = new BlastEmailThread(emails,subject,content);
blastEmailThread.start();
}