工具:java
ab -n [请求总数] -c [本次请求的并发数是50] [url] 例如:ab -1000 -c 50 http://www.baidu.com
一个图形化的工具,功能很强大编程
T一、T二、T3每次执行都会将计数器减1,线程A在计数器减为0的时候,才会执行。并发
可以保证某一个线程在其余线程执行完以后再执行的需求工具
同一时刻并行的线程数量性能
主要用来控制同时并发数测试
并发场景模拟网站
public class ConcurrencyTest { // 请求总数 public static int clientTotal = 5000; // 同时并发执行的线程数 public static int threadTotal = 200; public static int count = 0; public static void main(String[] args) throws Exception { ExecutorService executorService = Executors.newCachedThreadPool(); final Semaphore semaphore = new Semaphore(threadTotal); final CountDownLatch countDownLatch = new CountDownLatch(clientTotal); for (int i = 0; i < clientTotal ; i++) { executorService.execute(() -> { try { semaphore.acquire(); add(); semaphore.release(); } catch (Exception e) { log.error("exception", e); } countDownLatch.countDown(); }); } countDownLatch.await(); executorService.shutdown(); log.info("count:{}", count); } private static void add() { count++; } }