package action.user; import java.util.concurrent.CyclicBarrier; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; public class UserLoginExtActionRuntimeTest { public static void main(String[] args) { //设置并发数量 int count=10; //线程池准备 CyclicBarrier cyclicBarrier = new CyclicBarrier(count); ExecutorService executorService = Executors.newFixedThreadPool(count); //开始时间 long now = System.currentTimeMillis(); for (int i = 0; i < count; i++) { executorService.execute(new UserLoginExtActionRuntimeTest().new Task(cyclicBarrier,i)); } executorService.shutdown(); while (!executorService.isTerminated()) { try { Thread.sleep(10); } catch (InterruptedException e) { e.printStackTrace(); } } } public class Task implements Runnable{ private CyclicBarrier cyclicBarrier; private int count; public Task(CyclicBarrier cyclicBarrier, int count) { this.cyclicBarrier = cyclicBarrier; this.count = count; } @Override public void run() { try { //等待所有任务准备就绪 cyclicBarrier.await(); //测试路径 /* String href="http://localhost:8080/App/Se?id="+count; System.err.println(count); URL url = new URL(href); InputStream inputStream = url.openStream();*/ UserLoginExtActionTest c = new UserLoginExtActionTest(); c.connect(20000, "10.1.166.108"); } catch (Exception e) { System.out.println("出现超时的线程"+count); e.printStackTrace(); } } } }