关于定时器的本地启动配置及任务执行

本文档介绍了如何在本地配置并启动Quartz定时器任务,通过示例代码展示了任务执行过程,包括加载配置、防止进程退出等步骤。任务每30分钟执行一次,若在本地测试,可调整为3分钟执行一次。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

public class QuartzApplication {
    private static final Log LOG = LogFactory.getLog(QuartzApplication.class);
    
     /**
     * @param args
     */
    @SuppressWarnings("resource")
    public static void main(String[] args)
    {
        LOG.info("ApplicationContext init...");
        new ClassPathXmlApplicationContext("classpath*:applicationContext-quartz.xml");
        LOG.info("ApplicationContext load complete.");
        // 防止进程退出
         synchronized (QuartzApplication.class) {
             try {
                 QuartzApplication.class.wait();
            } catch (InterruptedException e) {
                LOG.error(e.getMessage(),e);
            }
         }
    }
}

 

 

 

 

//是否成功
                String result_code ="";
                String result_msg="";
                if(json_data!=null)
                {
                    result_code = json_data.getString("errorCode");
                    //失败原因
                    result_msg = json_data.getString("errorMessage");
                }else
                {
                    result_msg="GetWharfCanbinetNum 没有返回完整数据";
                }
                
                if(!"0000".equals(result_code)){
                    logger.error("GetWharfCanbinetNum error:"+result_msg);
                }else 
                {
                    //解析json里面包含的containers的list
                    JSONArray containers = json_data.getJSONArray("containers");
                    
                    for(Object entity : containers) 
                    {
                        JSONObject entityJson = JSONObject.parseObject(entity.toString());
                        // entityJson解析出来的属性映射到实体类
                        System.out.println(entityJson);
                        //SO表
                        String SoCode=entityJson.getString("shippingOrderNo");
    
                        //箱号
                        String BoxCode=entityJson.getString("containerNo");
                        //箱关联号
                        String containerRefNo=entityJson.getString("containerRefNo");
                        
                        //仓库箱动态查询
                        LOG.info("GetEntrepotBoxState--strat");
                        String result_data=klDataInService.GetEntrepotBoxState(SoCode, BoxCode);
                        LOG.info("GetEntrepotBoxState--end"+result_data);
                        
                        //仓库箱动态存库
                        LOG.info("saveWarehouse--strat");
                        klDataInService.saveWarehouse(result_data);
                        LOG.info("saveWarehouse--end"+result_data);
                        
                        //码头进出口作业动态,码头箱动态
                        LOG.info("GetWharfImpExpDynOpe--strat");
                        String result_data2=klDataInService.GetWharfImpExpDynOpe("", BoxCode, containerRefNo);
                        LOG.info("GetWharfImpExpDynOpe--end"+result_data2);
                        
                        //仓码箱动态存库
                        LOG.info("saveStorehouseCode--strat");
                        klDataInService.saveStorehouseCode(result_data2, SoCode, BoxCode, containerRefNo);
                        LOG.info("saveStorehouseCode--end"+result_data2);
                        
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }            
        if (LOG.isInfoEnabled()) {
            LOG.info("SoKLDataInJob 导入数据   End!!!!");
        }

 

该定时器任务执行时间间隔为30分钟一次,如果在本地测试定时器任务,则用debug模式启动QuartzApplication这个类,任务配置时间(com.ec.scheduler.kldata.BoshipJob=0 0/3 0 * * ?)3分钟一次。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值