1)
See the samples below.import java.util.*;class MyTimeTask extends TimerTask {
public static final int MAX_TARDINESS = 10000;
private String name;
public MyTimeTask(String name) {
this.name = name;
}
public void run() {
if (System.currentTimeMillis() - scheduledExecutionTime() >= MAX_TARDINESS) {
return; // Too late; skip this execution.
}
System.out.println("name = " + name);
// Perform the task
}
}public class TestProg {
public static void main(String[] args) throws Exception {
Timer timer = new Timer();
timer.schedule(new MyTimeTask("helo universe"), 1000);
Thread.sleep(2000);
}
}2) System.getCurrentTimeMills();
See the samples below.import java.util.*;class MyTimeTask extends TimerTask {
public static final int MAX_TARDINESS = 10000;
private String name;
public MyTimeTask(String name) {
this.name = name;
}
public void run() {
if (System.currentTimeMillis() - scheduledExecutionTime() >= MAX_TARDINESS) {
return; // Too late; skip this execution.
}
System.out.println("name = " + name);
// Perform the task
}
}public class TestProg {
public static void main(String[] args) throws Exception {
Timer timer = new Timer();
timer.schedule(new MyTimeTask("helo universe"), 1000);
Thread.sleep(2000);
}
}2) System.getCurrentTimeMills();
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货