java计数
计数
package com.demo; import java.util.Timer; import java.util.TimerTask; import java.util.concurrent.atomic.AtomicInteger; /** * Created by admin on 2018/5/15 16:12. */ public class Test { public static void main(String[] args) { for (int i = 0; i < 3; i++) { Timer timer = new Timer(); timer.schedule(new TimerTask() { AtomicInteger count = new AtomicInteger(0); @Override public void run() { count.incrementAndGet(); System.out.println("正在运行的线程:" + Thread.currentThread().getName() + ",数量:" + count.get()); if (count.get() == 10) { timer.cancel(); System.out.println(Thread.currentThread().getName() + "线程结束...."); } } }, 0, 1000); } } }