Support automatic recovery downtime trigger a one-time or periodic task execution Package -easyTask

easyTask

  • Easy to trigger a one-time or periodic task execution toolkit to support massive, high concurrency, high availability, downtime automatic recovery tasks
  • Open source projects address: https: //github.com/liuche51/easyTask a lot of attention

Usage scenarios

  • It requires precise moment seconds to trigger a task to perform. Such as order transaction is completed after 24 hours if the customer fails evaluation, the system automatically gives the evaluation.
  • You need to periodically perform a task. For example, 18 o'clock every day to remind employees to work off.

Features

  • Simple to use
  • Second-level precision mandate implementation plan
  • Support the massive task presented to the Executive
  • Support high concurrent execution of tasks
  • Support mission persistence, automatic recovery tasks planned downtime
  • Support for custom thread pool, mission persistence save path

Architecture

Getting started

  • pom Add Reference
<dependency>
    <groupId>com.github.liuche51</groupId>
    <artifactId>easyTask</artifactId>
    <version>1.0.1</version>
</dependency>
  • Good class Define custom task you want to perform the task class you want to perform
public class CusTask1 extends Schedule implements Runnable {
    private static Logger log = LoggerFactory.getLogger(CusTask1.class);

    @Override
    public void run() {
        Map<String, String> param = getParam();
        if (param != null && param.size() > 0)
            log.info("任务1已执行!姓名:{} 生日:{} 年龄:{} 线程ID:{}", param.get("name"), param.get("birthday"), param.get("age"),param.get("threadid"));

    }
}
  • Simple application sample code Simply apply the sample code
public class Main {
    private static Logger log = LoggerFactory.getLogger(Main.class);
    private static AnnularQueue annularQueue=AnnularQueue.getInstance();
    private static Object obj=new Object();
    public static void main(String[] args){
        allcustomSimpleSetTest();
    }
    static void allcustomSimpleSetTest(){
        try {
            annularQueue.start();
            CusTask1 task1 = new CusTask1();
            task1.setEndTimestamp(ZonedDateTime.now().plusSeconds(10).toInstant().toEpochMilli());
            Map<String,String> param=new HashMap<String,String>(){
                {
                    put("name","刘彻");
                    put("birthday","1988-1-1");
                    put("age","25");
                    put("threadid",String.valueOf(Thread.currentThread().getId()));
                }
            };
            task1.setParam(param);new=
            CusTask1 task2 CusTask1();
            task2.setPeriod(30);
            task2.setImmediateExecute(true);
            task2.setTaskType(TaskType.PERIOD);
            task2.setUnit(TimeUnit.SECONDS);
            Map<String,String> param2=new HashMap<String,String>(){
                {
                    put("name","Jack");
                    put("birthday","1986-1-1");
                    put("age","32");
                    put("threadid",String.valueOf(Thread.currentThread().getId()));
                }
            };
            task2.setParam(param2);
            annularQueue.submit(task1);
            annularQueue.submit(task2);
            obj.wait();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

Notice

  • This component has been under Windows centos and do appropriate tests, currently not used in a production environment
  • In order to better ensure automatic fault recovery tasks, self-defined procedures mandate saved persistent file path (file path defined different for different applications as well, so as not to be covered by other applications), and make sure read and write permissions. If you're running jar package, the default file in the same directory; if the war package to run under tomcat, the default file in the bin directory of tomcat.
  • If you encounter problems in the course, you can submit it here

Guess you like

Origin www.cnblogs.com/liuche/p/10981291.html