我有代码,我在那里安排任务使用java.util.Timer.我环顾四周,看到ExecutorService可以做同样的事情.所以这个问题,你有没有使用Timer和Timer计划任务,一个人使用另一个人的好处是什么?
还想检查是否有人使用过该ExecutorService课程并遇到了Timer为他们解决的任何问题.
最近我一直在使用大数字循环打印出来Hello World:
int counter = 0;
while(true) {
//loop for ~5 seconds
for(int i = 0; i < 2147483647 ; i++) {
//another loop because it's 2012 and PCs have gotten considerably faster :)
for(int j = 0; j < 2147483647 ; j++){ ... }
}
System.out.println(counter + ". Hello World!");
counter++;
}
Run Code Online (Sandbox Code Playgroud)
我知道这是一个非常愚蠢的方法,但我还没有在Java中使用任何计时器库.怎么会修改上面打印每说3秒?