有源码吗?
有源码吗?
有源码吗?
2017-05-17
package com.may.seventy; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.TimerTask; /** * Created by junfeng on 17/5/17. */ public class MyTimerTask extends TimerTask { private String name; public MyTimerTask(String inputName){ name = inputName; } @Override public void run() { Calendar calendar = Calendar.getInstance(); SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); System.out.println("Current exec name is:"+name); } public String getName() { return name; } public void setName(String name) { this.name = name; } }
package com.may.seventy; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Timer; /** * Created by junfeng on 17/5/17. */ public class MyTimer { public static void main(String[] args) { Timer timer = new Timer(); MyTimerTask myTimerTask = new MyTimerTask("NO.1"); //timer.schedule(myTimerTask,1000L,5000l); Calendar calendar = Calendar.getInstance(); SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); System.out.println(sf.format(calendar.getTime())); calendar.add(Calendar.SECOND,3); // myTimerTask.setName("test1"); // timer.schedule(myTimerTask,calendar.getTime()); // myTimerTask.setName("test2"); // timer.schedule(myTimerTask,calendar.getTime(),3000); myTimerTask.setName("test3"); timer.schedule(myTimerTask,2000); } }
举报