TimerUtil.java 1.48 KB
Newer Older
邓实川 committed
1
package cn.timer.api.utils.schedule;
yuquan.zhu committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66

import cn.hutool.core.date.DateTime;
import cn.hutool.cron.CronUtil;

public class TimerUtil {

	/**
	 * 
	 * @param path * * * * * ?
	 */
	public static void timer(String path) {
		CronUtil.setMatchSecond(true);
		CronUtil.schedule(path, new Runnable() {

			@Override
			public void run() {
				System.err.println("maye");
			}
		});

	}

	public static int count = 0;

	public void start() {
		System.out.printf("第%d次执行定时任务,当前时间:%s\n", ++count, DateTime.now().toString());
	}

//	public static void timer1(String path) {
//		CronUtil.setMatchSecond(true);
//		CronUtil.schedule("*/2 * * * * *", new Task() {
//		    @Override
//		    public void execute() {
//		    	
//		    }
//		});
//		CronUtil.start();
//		Setting cronSetting = null;
//		CronUtil.setCronSetting(cronSetting);
//		CronUtil.schedule(cronSetting);
//	}

	public static void main(String[] args) {

		CronUtil.start();
		CronUtil.stop();
//		Calendar calendar = Calendar.getInstance();
//		SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//		System.err.println(sf.format(calendar.getTime()));
//
//		calendar.set(2019, 11, 17, 19, 42, 30);
//		// calendar.set(year, month, date, hourOfDay, minute, second);参数均为int
//
//		Timer timer = new Timer();
//		timer.schedule(new TimerTask() {
//			@Override
//			public void run() {
//				System.err.println("666:" + sf.format(calendar.getTime()));
//				timer.cancel();
//			}
//		}, calendar.getTime());

	}

}