@Schedule开始两次

时间:2019-06-03 12:49:56

标签: java java-ee tomee

该程序每天凌晨4点启动,但是每天计划启动两次,我已经检查了任何周期,但是一切都井井有条。 为什么总是总是启动两次? 我该怎么解决?

import javax.ejb.LocalBean;
import javax.ejb.Schedule;
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;

@Stateless
@LocalBean
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public class RichiamiSync {
    @Schedule (minute = "00", hour = "04")

    public  void main() {

        try {
            Logica.esegui();
            }
            catch (Exception e) {
                Log.write("ERROR  " + e);
                Log.write("---------------------ERRORE FATALE IL PROGRAMMA E' STATO ARRESTATO-------------------------");   
                }
        Ottimizza.sql();

        Log.sendEmail();


    }




}

最初,这些方法的注释如下:

@Singleton
@LocalBean
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)

但是在另一个问题中,他们说使用无状态它将解决,现在问题总是相同的

1 个答案:

答案 0 :(得分:0)

这是解决方案:

@Singleton
@LocalBean
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public class ServerStartStop {

    private ExecutorService es2 = Executors.newSingleThreadExecutor();
    private Future<Void> operazioniAggiornamentoUI =null;
    
    
    @Schedule(hour = "*" ,minute = "*",second = "*/10", persistent = false)
    public void AggiornamentoUI(Timer timerInfo) {
        
        if (operazioniAggiornamentoUI!=null)
            if(!operazioniAggiornamentoUI.isDone())
                return;
        
        
        Callable<Void> callableObj = () -> { try {

            GestoreAcquisizioneOrdiniUI.aggiornaUiAcquisizioneOrdini();
            
            
            
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;
        };
        
        
        
        operazioniAggiornamentoUI=es2.submit(callableObj);
        
        
        
        
    }}