- import java.util.concurrent.Executors;
- import java.util.concurrent.TimeUnit;
- public class Demo02 {
- static int i = 0;
- public static void main(String[] args) {
- Executors.newScheduledThreadPool(1).scheduleAtFixedRate(new Runnable(){
- public void run() {
- i++;
- if(i<=100){
- System.out.println(i);
- }else{
- System.exit(0);
- }
- }
- }, 0, 1, TimeUnit.MICROSECONDS);
- }
- }
复制代码 用并发线程也可以实现,当然很麻烦,但也是一种方式。。 |