static void runTime(){
//10分钟之内5秒一次 int time = 60000*10; int count = time/5000; int i = 0 ; new Thread().start(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); while (i < count) { if(i == 0) { System.out.println("线程开始-------->当前的系统时间为:" + sdf.format(new Date())); } try { Thread.sleep(1000*5); System.out.println("第"+i+"次执行,当前的系统时间为:" + sdf.format(new Date())); i++; //条件过滤停止 if(i >= 2) { break; } } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } System.out.println("线程停止-------->当前的系统时间为:" + sdf.format(new Date())); }
//运行效果...