首页 新闻 搜索 专区 学院

java 定时任务 重复执行问题

0
悬赏园豆:10 [待解决问题]


 INFO (ReadCRLogTask.java:39) - Start________________Log : 2016-08-05 15:53:40
 INFO (ReadCRLogTask.java:41) - readCabRadioLog : 2016-08-05 15:53:40
 INFO (ReadCRLogTask.java:39) - Start________________Log : 2016-08-05 15:53:41
 INFO (ReadCRLogTask.java:41) - readCabRadioLog : 2016-08-05 15:53:41
 INFO (ReadCRLogTask.java:45) - insertCabRadioData : 2016-08-05 15:53:46
 INFO (ReadCRLogTask.java:45) - insertCabRadioData : 2016-08-05 15:53:46
 INFO (ReadCRLogTask.java:49) - coverageByLocation : 2016-08-05 15:53:46
 INFO (ReadCRLogTask.java:53) - degradedCoverageLocations : 2016-08-05 15:53:46
 INFO (ReadCRLogTask.java:49) - coverageByLocation : 2016-08-05 15:53:46
 INFO (ReadCRLogTask.java:57) - unreportedCellChangeLocations : 2016-08-05 15:53:46
 INFO (ReadCRLogTask.java:53) - degradedCoverageLocations : 2016-08-05 15:53:46
 INFO (ReadCRLogTask.java:61) - unreportedTransponders : 2016-08-05 15:53:46
 INFO (ReadCRLogTask.java:57) - unreportedCellChangeLocations : 2016-08-05 15:53:46
 INFO (ReadCRLogTask.java:65) - abnormalCellChange : 2016-08-05 15:53:46
 INFO (ReadCRLogTask.java:61) - unreportedTransponders : 2016-08-05 15:53:46
 INFO (ReadCRLogTask.java:65) - abnormalCellChange : 2016-08-05 15:53:46
 INFO (ReadCRLogTask.java:69) - End__________________Log : 2016-08-05 15:55:50
 INFO (ReadCRLogTask.java:69) - End__________________Log : 2016-08-05 15:55:50

定时任务每天执行一次之前还正常 ,最近为什么会执行两次??

并没有对这块做任何修改?

求思路

指点一下大概可能也许是什么问题?

问题补充:

 private static final String READ_LOG_TIME = "00:00:01";
    
    private static final String READ_LOG_PATH = "E:\\monitor\\CabRadioLog";
    
    private IReadCRLogService services;
      
    @Override
    public void run()
    {
        try
        {   
            log.info("Start________________Log : "+ CommonUtil.getDatetimeByLong(System.currentTimeMillis()));
            
            log.info("readLog : " + CommonUtil.getDatetimeByLong(System.currentTimeMillis()));
            
            services.readLog(Task.getPath());
            
            log.info("insertData : " + CommonUtil.getDatetimeByLong(System.currentTimeMillis()));
            
            services.insertData();     
            
            log.info("coverageByLocation : " + CommonUtil.getDatetimeByLong(System.currentTimeMillis()));
            
            services.coverageByLocation();                   
           
            log.info("degradedCoverageLocations : " + CommonUtil.getDatetimeByLong(System.currentTimeMillis()));
            
            services.degradedCoverageLocations();          
            
            log.info("unreportedCellChangeLocations : " + CommonUtil.getDatetimeByLong(System.currentTimeMillis()));
            
            services.unreportedCellChangeLocations();     
            
            log.info("unreportedTransponders : " + CommonUtil.getDatetimeByLong(System.currentTimeMillis()));
            
            services.unreportedTransponders();       
            
            log.info("abnormalCellChange : " + CommonUtil.getDatetimeByLong(System.currentTimeMillis()));
            
            services.abnormalCellChange();  
            
            log.info("End__________________Log : " + CommonUtil.getDatetimeByLong(System.currentTimeMillis()));
        }
        catch (Exception e)
        {
            log.error("[ReadCRLogTask-run]The error = " + e.getMessage());
        }
    }

 

 

   //读取 log日志
        if (CommonUtil.isTimeToWork(Task.getReadCRLogTime()))
        {
            try
            {
                Task task = (Task)CommonUtil.getBean("Task");
                task.start();
            }
            catch (Exception e)
            {
                log.error("[TIMER] backupDatabaseTask start failed. e=" + e.getMessage());
            }
        }

遥远的守望的主页 遥远的守望 | 初学一级 | 园豆:96
提问于:2016-08-05 10:21
< >
分享
所有回答(3)
0

代码呢?

JokerJason | 园豆:210 (菜鸟二级) | 2016-08-05 10:22

定时这块没做修改,两天前还正常(打印一次),今天就每次调试都打印两次。。。

支持(0) 反对(0) 遥远的守望 | 园豆:96 (初学一级) | 2016-08-05 10:45

@遥远的守望: IReadCRLogService这个代码补一下

支持(0) 反对(0) JokerJason | 园豆:210 (菜鸟二级) | 2016-08-05 11:15

@JokerJason: 

public interface IReadCRLogService
{
    public void readCabRadioLog(String path) throws Exception;

    public void coverageByLocation() throws Exception;
    
    public void insertCabRadioData() throws Exception;  
    
    public void degradedCoverageLocations() throws Exception;
    
    public void unCellChangeLocations() throws Exception;
    
    public void unTransponders() throws Exception;
    
    public void abnormalCellChange() throws Exception;
}

支持(0) 反对(0) 遥远的守望 | 园豆:96 (初学一级) | 2016-08-05 11:21

@JokerJason: 

修改这个对定时任务有影响么?

支持(0) 反对(0) 遥远的守望 | 园豆:96 (初学一级) | 2016-08-05 11:22

@遥远的守望: 觉得你代码还没给完全啊  不过估计是线程不安全  在关键代码上加Synchronized  试一下 或者把完整代码发我邮箱 zh-jia-ch@163.com 再帮你看看  

支持(0) 反对(0) JokerJason | 园豆:210 (菜鸟二级) | 2016-08-05 13:15

@JokerJason:

恩 谢谢, 我试试看....

--! 代码不能外发,没权限 . . .

支持(0) 反对(0) 遥远的守望 | 园豆:96 (初学一级) | 2016-08-05 14:11

@JokerJason: 

@Override
    public void run()
    {
        try
        {   
            excuteCRLogTask();
        }
        catch (Exception e)
        {
            log.error("[ReadCRLogTask-run]The error = " + e.getMessage());
        }
    }

    private synchronized void excuteCRLogTask() throws Exception

   加了这个,貌似不管用...

支持(0) 反对(0) 遥远的守望 | 园豆:96 (初学一级) | 2016-08-05 14:29
0

代码呢?

之奇一昂 | 园豆:1421 (小虾三级) | 2016-08-05 10:38

定时这块代码没做啥修改.

前两天还正常,今天就打印两次..

支持(0) 反对(0) 遥远的守望 | 园豆:96 (初学一级) | 2016-08-05 10:46
0

用定时器或者用线程池执行周期性任务.这样不容易出错.

zzjbook | 园豆:215 (菜鸟二级) | 2016-08-07 15:57
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册