并发测试

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;

/**
 * 并发测试
 *
 * @author yibin
 * @create 2018-10-08 12:56
 **/
public class ConcurrentTestUtil {

    private static final int THREADNUM = 100;

    public static  void test(T t,Consumer consumer,int threadNum){
        CountDownLatch countDownLatch = new CountDownLatch(threadNum);
        for (int i=0;i{
                try {
                    countDownLatch.await();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                consumer.accept(t);
            }).start();
            countDownLatch.countDown();
        }
    }

    public static  void test(T t,Consumer consumer){
        test(t,consumer,THREADNUM);
    }

}


 

你可能感兴趣的:(并发测试)