java spring调度程序在产品中多次运行

问题描述 投票:0回答:1

我正在运行一个 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);
        }
    }
}
java spring scheduled-tasks crontrigger
1个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.