a- import java.util.Calendar;
- import java.util.Timer;
- import java.util.TimerTask;
- public class AlternateTimer {
- /**
- * 交替运行的两个定时器比如 2 4 2 4 2 4 2 4....
- */
- public static void main(String[] args) {
- new Timer().schedule(new TimerTask(){
- @Override
- public void run() {
- System.out.println("Booming 1");
- new Timer().schedule(new TimerTask(){
- @Override
- public void run() {
- System.out.println("Booming 2");
- }
- }, 2000);
- }
- }, 0,6000);
- //输出秒
- while(true){
- System.out.println(Calendar.getInstance().get(Calendar.SECOND));
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
- }
复制代码
|
|