Package com.proj.thread;
Import Java.text.SimpleDateFormat;
Import Java.util.Date;
Import Java.util.Timer;
Import Java.util.TimerTask; /** * 1, the task in the program after two seconds after the first explosion * 2, after every 3 seconds after the explosion, and then another 5 seconds to perform, so the cycle ... * * * * * * * * * public class Mytimertask extends timertask{private
static int count = 0; @Override public void Run () {++count;
The number of explosions counter SOP ("the" +count+ "the second explosion, time:" +getdate () + "--bombing");
if (count%2==1) {new Timer (). Schedule (New Mytimertask (), 3000);
}else{new Timer (). Schedule (New Mytimertask (), 5000);
The private static String getDate () {Date date = new Date ();
SimpleDateFormat SDF = new SimpleDateFormat ("Hh:mm:ss");
String datestr = Sdf.format (date);
return datestr;
protected static void SOP (String string) {System.out.println (string); public static void Main (string[] args) {System.out.println (GetDate ()); Start recording time New Timer (). Schedule (New Mytimertask (), 2000);
First Explosion}}