标签:idt width dia try 年龄 使用 ndt sage 开源
<dependency> <groupId>com.github.liuche51</groupId> <artifactId>easyTask</artifactId> <version>1.0.1</version> </dependency>
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")); } }
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); CusTask1 task2 = new 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(); } }
支持宕机自动恢复触发一次性或周期性任务执行的组件包-easyTask
标签:idt width dia try 年龄 使用 ndt sage 开源
原文地址:https://www.cnblogs.com/liuche/p/10981291.html