多线程计数器

package com.wk.thread.count;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * 测试AtomicInteger与普通int值在多线程下的递增操作
 */
public class TestAtomicInteger {
	final static int threads = 123;//线程数
	final int singleThread = 456;//每次线程执行的循环数
	static AtomicInteger atomic = new AtomicInteger(0);//初始化计数器
	public static void main(String[] args) throws InterruptedException {
		CountDownLatch countDownLatch = new CountDownLatch(threads);//初始化倒序计数器
		ExecutorService executors = Executors.newFixedThreadPool(threads);//固定线程池
		for(int i= 0;i


参考地址:

http://blog.csdn.net/longerandlonger/article/details/8276869(一个使用线程计数器的例子)

http://www.jb51.net/article/55373.htm(Java中对AtomicInteger和int值在多线程下递增操作的测试

http://blog.csdn.net/is_zhoufeng/article/details/8151092(java线程池 与 同步计数器CountDownLatch的使用)

你可能感兴趣的:(多线程计数器)