package com.java214.Main; import java.util.concurrent.CountDownLatch; import org.springframework.context.ApplicationContext; import org.springframework.context.support.FileSystemXmlApplicationContext; import com.java214.model.Blog; import com.java214.service.BlogService; /** * 测试系统的并发量 * @author Administrator * */ public class Main { ApplicationContext ac = new FileSystemXmlApplicationContext("classpath:spring/applicationContext-*.xml"); BlogService blogService = ac.getBean(BlogService.class); private void testThread() throws InterruptedException { final CountDownLatch startGate = new CountDownLatch(1); final CountDownLatch endGate = new CountDownLatch(100); for (int i = 0; i < 20; i++) { new Thread("" + i) { public void run() { try { startGate.await(); } catch (InterruptedException e) { e.printStackTrace(); } Blog blog = blogService.selectBlogById(95); System.out.println(Thread.currentThread().getName() + "-" + blog.getClicknum()); endGate.countDown();// 任务执行完毕,计数器减1; } }.start(); // Thread.sleep(100); } long start = System.nanoTime(); startGate.countDown(); // 到此处,说明所有线程准备就绪,可以开始执行任务 endGate.await();// 阻塞等待所有线程执行完毕. long end = System.nanoTime(); System.out.println((end - start) + " ns"); } public static void main(String[] args) { //new Main().testThread(); } }
最近下载更多
最近浏览更多
yqyqyqyqy LV4
昨天
xiongM LV4
4月20日
g815835618 LV2
4月12日
zolscy LV12
4月2日
微信网友_6927932988952576 LV12
3月30日
xiaopengzep LV1
3月24日
罗清晨 LV11
2月28日
yxzzxy LV3
2月18日
admin_z LV22
1月29日
liiiyou LV1
1月26日