java spring scheduler在prod

时间:2018-03-21 09:10:20

标签: java spring taskscheduler crontrigger

  

我正在运行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);
    }
}

}

1 个答案:

答案 0 :(得分:0)

检查如何在生产容器上配置实例。如果已设置,请关闭自动缩放功能。批处理程序在任何给定点都不应运行多个实例。

相关问题