首页>代码>基于SSM的技术博客系统>/Art_Blog/src/main/java/com/java214/Main/Main.java
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();
  }
}
最近下载更多
lpwgzy  LV5 2023年10月9日
全栈小白  LV34 2023年9月11日
yunYUN123  LV1 2023年5月18日
tyyeng  LV18 2022年12月27日
利民提提  LV3 2022年11月20日
lilong007  LV20 2022年10月21日
cyx123456  LV6 2022年8月13日
getset  LV8 2022年6月26日
zhangjilu  LV18 2022年6月11日
testuser1234567  LV24 2022年5月23日
最近浏览更多
yqyqyqyqy  LV4 昨天
xiongM  LV4 4月20日
g815835618  LV2 4月12日
zolscy  LV12 4月2日
xiaopengzep  LV1 3月24日
罗清晨  LV11 2月28日
yxzzxy  LV3 2月18日
admin_z  LV22 1月29日
liiiyou  LV1 1月26日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友