[英]java spring scheduler running multiple times in prod
我正在運行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"/>
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);
}
}
}
檢查如何在生產容器上配置實例。 如果已設置,請關閉自動縮放功能。 批處理程序在任何給定點都不應運行多個實例。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.