首页>代码>基于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();
  }
}
最近下载更多
TY0165  LV20 2024年6月21日
lpwgzy  LV5 2023年10月9日
全栈小白  LV35 2023年9月11日
yunYUN123  LV1 2023年5月18日
tyyeng  LV18 2022年12月27日
利民提提  LV3 2022年11月20日
lilong007  LV23 2022年10月21日
cyx123456  LV6 2022年8月13日
getset  LV8 2022年6月26日
zhangjilu  LV18 2022年6月11日
最近浏览更多
xiaoaitx  LV8 1月2日
萌了个乖乖  LV12 2024年12月26日
三秋桂子  LV1 2024年12月22日
ma406805131  LV19 2024年12月18日
krispeng  LV14 2024年11月20日
897258976  LV8 2024年8月29日
TY0165  LV20 2024年6月21日
mc152921 2024年5月29日
暂无贡献等级
yellow_flowers  LV8 2024年4月26日
yqyqyqyqy  LV4 2024年4月24日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友