使用TimerTask每隔2秒4秒交替执行程序

package com.zhlk.thread;

import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

public class TraditionalTimerTest {
	/**
	 * 创建日期:2017-3-4下午9:32:26
	 * 作者:lvguanghui
	 */
     PRivate static int count=0;
	public static void main(String[] args) {
		 class MyTimerTask extends TimerTask {
		 	 public void run() {
		 		 count=(count+1)%2;
				 System.out.println("nihao");	
			       new Timer().schedule(new MyTimerTask(), 2000+2000*count);	 
				}
			}
	  
		new Timer().schedule(new MyTimerTask(), 2000);
	   while(true){
		System.out.println("第"+new Date().getSeconds()+"秒");
		  	try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	   }
	  
}
}