使用elastic-job创建定时任务

配置文件

 




    


    
    

    

    



package com.elasticjob;

import com.bicon.panwen.Crawl2222;
import com.bicon.xpath.exception.XpathSyntaxErrorException;
import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Resource;
import java.util.Date;

public class PanwenSimpleJob implements SimpleJob {

    private static final Logger LOGGER = LoggerFactory.getLogger(PanwenSimpleJob.class);

    @Resource
    private Crawl2222 crawl2222;

    @Override
    public void execute(ShardingContext shardingContext) {

        System.out.println(String.format("------Thread ID: %s, 任务总片数: %s, " +
                        "当前分片项: %s.当前参数: %s,"+
                        "当前任务名称: %s.当前任务参数: %s"
                ,
                Thread.currentThread().getId(),
                shardingContext.getShardingTotalCount(),
                shardingContext.getShardingItem(),
                shardingContext.getShardingParameter(),
                shardingContext.getJobName(),
                shardingContext.getJobParameter()

        ));

        LOGGER.error("开始时间"+new Date());
        LOGGER.error("中国裁判文书网定时任务开始执行");
        try {
            crawl2222.init();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (XpathSyntaxErrorException e) {
            e.printStackTrace();
        }
        LOGGER.error("中国裁判文书网定时任务结束");


    }
}

 

你可能感兴趣的:(java)