我正在运行一个 spring(cron) 的 Web 应用程序调度程序来发送通知邮件,当在本地服务器上运行时,它运行良好,但在生产模式下,它会发送多封邮件。
<bean id="EmailNotificationScheduledTask" class="com.prism.utils.EmailNotificationTask" />
<task:scheduled-tasks scheduler="scheduler">
<task:scheduled ref="EmailNotificationScheduledTask" method="run" cron="0 0 10 * * MON"/>
</task:scheduled-tasks>
<task:scheduler id="scheduler" pool-size="1"/>
</beans>
public class EmailNotificationTask extends TimerTask{
@Override
public void run() {
synchronized (this) {
sendPropertyNotificationEmail();
}
//}
}
@SuppressWarnings("unchecked")
public void sendPropertyNotificationEmail(){
try{
//Mail sending logic
}
} catch (DAOException ee) {
_logger.error("Error while sending notification messages", ee);
}
}
}
检查实例在生产容器上的配置方式。关闭自动缩放(如果已设置)。批处理程序在任何给定点都不应该运行多个实例。