package com.cn.gbx;import java.util.Date;import java.util.Timer;import java.util.TimerTask;//class MyTimerTask extends TimerTask {// private static int x = 0;// { x = (x + 1) % 2; }// @Override// public void run() {// // System.out.println("booming!");// if ((x & 1) == 0) {// new Timer().schedule(new MyTimerTask(), 4000);// } else if ((x & 1) == 1) {// new Timer().schedule(new MyTimerTask(), 2000);// }// }//}class MyTimerTask1 extends TimerTask{ @Override public void run() { System.out.println("booming !"); new Timer().schedule(new MyTimerTask2(), 2000); }}class MyTimerTask2 extends TimerTask{ @Override public void run() { System.out.println("booming !"); new Timer().schedule(new MyTimerTask1(), 4000); }}public class TestThread { public static void main(String[] args) { //利用奇数偶数来判断// new Timer().schedule(// new MyTimerTask(), // 2000); // A B 循环调用 new Timer().schedule(new MyTimerTask1(), 1000); //来输出时间 while (true) { System.out.println(new Date().getSeconds()); try { Thread.sleep(1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }}