public class Main {
public static void main(String[] args) {
TimerTask timerTask = new TimerTask() {
@Override
public void run() {
System.out.println("当前线程:" + Thread.currentThread().getName() + " 当前时间" + LocalDateTime.now());
}
};
// 在指定延迟0毫秒后开始,随后地执行以2000毫秒间隔执行timerTask
new Timer().schedule(timerTask, 0L, 2000L);
System.out.println("当前线程:" + Thread.currentThread().getName() + " 当前时间" + LocalDateTime.now());
}
}
java延迟一段时间执行任务
于 2022-08-18 21:52:40 首次发布
1123

被折叠的 条评论
为什么被折叠?



