---
title: "Timer"
author: "IT009"
date: "2011-06-30T16:54:05Z"
tags: []
categories: ["编程语言"]
slug: "timer"
draft: false
lastmod: "2011-07-30T08:12:19Z"
id: 1111312
url: "https://it009.iteye.com/blog/1111312"
---

public class TimerTasks {

	public static void main(String args) {
		Timer time = new Timer();
		Date startDate = new Date();
		TimerTasks task = new TimerTasks();
		final DriectoryManagement dmg = task.new DriectoryManagement();
		time.schedule(new TimerTask() {

			@Override
			public void run() {
				// TODO Auto-generated method stub
				dmg.executes();
			}

		}, startDate, 1000);

		try {
			Thread.sleep(5000);
			time.cancel();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public class DriectoryManagement {
		int n;

		public void executes() {
			this.n++;
			System.out.println("n:" + n);
		}
	}
}


http://tech.ddvip.com/2008-01/119991257740150_2.html
http://my.chinaunix.net/space.php?uid=24426415&do=blog&id=77453
http://www.kklinux.com/html/shujukujishu/BD2/200901/13-2542.html
http://database.51cto.com/art/201008/217966.htm