我有一个用于发送电子邮件的方法。我希望锁定此方法,以便每次只能有一个线程访问它,而其余线程则可以同时排队。我应该使用synchronized关键字来同步该方法,还是使用Spring的@Transactional(propagation=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();
}