java 任务调度


package com.xh.task;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimerTask;

/**
 * 继承 java.util.TimerTask 重写run方法
 * 
 * @author Administrator
 * 
 */
public class MyTAsk extends TimerTask {

	private String userName;

	public MyTAsk() {

	}

	public MyTAsk(String userName) {
		this.userName = userName;
	}

	@Override
	public void run() {
		// SimpleDateFormat format=new SimpleDateFormat();
		// format.f
		try {
			System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ms").parse("2009-10-16 20:24:000").after(new Date()));
		} catch (ParseException e) {
			e.printStackTrace();
		}
		System.out.println("Hello "+userName);
	}

}

package com.xh.task;

import java.util.Timer;

public class MyTime {

	/**
	 * @param args  5秒后启动  每隔三秒调用一次
	 */
	public static void main(String[] args) {
		Timer time=new Timer();
		time.schedule(new MyTAsk("xiaohua"), 5000, 3000);
	}

}

你可能感兴趣的:(java,F#)