1.配置 ThreadPoolTaskExecutor bean

 
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <!-- 扫描注解 -->
<context:component-scan base-package="com.qi.quartz">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
</context:component-scan> <bean id="taskExecutor" name="taskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<!-- 核心线程数 线程池维护线程的最少数量 -->
<property name="corePoolSize" value="10" />
<!-- 线程池维护线程所允许的空闲时间 -->
<property name="keepAliveSeconds" value="200" />
<!-- 线程池维护线程的最大数量 -->
<property name="maxPoolSize" value="20" />
<!-- 线程池所使用的缓冲队列 -->
<property name="queueCapacity" value="100" />
<!-- 线程池对拒绝任务(无线程可用)的处理策略 ThreadPoolExecutor.CallerRunsPolicy策略 ,调用者的线程会执行该任务,如果执行器已关闭,则丢弃. -->
<property name="rejectedExecutionHandler">
<bean class="java.util.concurrent.ThreadPoolExecutor$CallerRunsPolicy" />
</property>
</bean> </beans> 2.controller使用

/**
* This file created at 2018年4月13日 下午3:06:57.
*
* Copyright (c) 2004-2014 AVTrace, Inc. All rights reserved.
*/
package com.avtrace.nlc.nms.listener;

import javax.annotation.Resource;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jms.listener.SessionAwareMessageListener;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
* @author 唐芝泉
* @since 1.0.0
*/
@Controller
@RequestMapping("/test")
public class test implements SessionAwareMessageListener<Message> {
Logger LOG = LoggerFactory.getLogger(test.class);
@Resource(name = "taskExecutor")
private ThreadPoolTaskExecutor taskExecutor;
@RequestMapping("/execute")
@ResponseBody
@Override
public void onMessage(Message message, Session session) throws JMSException {
taskExecutor.execute(new Runnable(){

public void run() {
try {
LOG.info("执行线程任务开始前");
Thread.currentThread().sleep(1000);
if (LOG.isDebugEnabled()) {
LOG.info("执行线程任务结束");
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}

});

//设置线程的存活时间
taskExecutor.setKeepAliveSeconds(60);
}

}

3、cmd f: (因为我把ad.exe放到f:\下)

<bean id="taskExecutor"
class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="4" /> <!-- 并发线程数,想达到真正的并发效果,最好对应CPU的线程数及核心数 -->
<property name="maxPoolSize" value="1000" /> <!-- 最大线程池容量 -->
<property name="queueCapacity" value="2000" /> <!-- 超过最大线程池容量后,允许的线程队列数 -->
</bean>

这里我是设置4并发数,最大线程池容量1000

F:\>ab -n 10000 -c 1000 http://192.168.40.21:8080/cctv/test/excute

这句命令表示10000次请求,1000个并发数 ,用时:1.206ms

比正常配置 10000*1000-4*1000=9996000

工具:链接: https://pan.baidu.com/s/1lg7BB-8OKSoluWOGjz03kw 密码: dz7i

多线程并发测试(apache ad)的更多相关文章

  1. Java接口多线程并发测试 (一)

    本文为作者原创,禁止转载,违者必究法律责任!!! 本文为作者原创,禁止转载,违者必究法律责任!!! Java接口多线程并发测试 一,首先写一个接口post 请求代码: import org.apach ...

  2. Selenium & Webdriver 远程测试和多线程并发测试

    Selenium & Webdriver 远程测试和多线程并发测试 Selenium Webdriver自动化测试,初学者可以使用selenium ide录制脚本,然后生成java程序导入ec ...

  3. Java接口多线程并发测试 (二)

    原文地址http://www.cnblogs.com/yezhenhan/archive/2012/01/09/2317636.html 这是一篇很不错的文章,感谢原博主的分享! JAVA多线程实现和 ...

  4. 利用Testng注释实现多线程并发测试

    Testng 是一款非常优秀的测试框架,真正从测试角度出发,为测试所想.在测试过程中我们经常会遇到对某一个场景做并发请求,主要想了解该程序在并发时是否会有异常或者没考虑到的其他情况,这时往往不是要做性 ...

  5. selenium从入门到应用 - 8,selenium+testNG实现多线程的并发测试

    本系列所有代码 https://github.com/zhangting85/simpleWebtest本文将介绍一个Java+TestNG+Maven+Selenium的web自动化测试脚本环境下s ...

  6. apache并发测试工具ab为什么测不准

    apache并发测试工具ab为什么测不准 发表于2年前(2013-03-21 12:13)   阅读(1146) | 评论(1) 1人收藏此文章, 我要收藏 赞0 3月21日 深圳 OSC 源创会正在 ...

  7. 利用Python多线程来测试并发漏洞

    需求介绍 有时候想看看Web应用在代码或者数据库层有没有加锁,比如在一些支付.兑换类的场景,通过多线程并发访问的测试方式可以得到一个结论. 步骤 1. Burp Suite安装插件 安装一个Copy ...

  8. webBench&ad网站并发测试工具

    webBench 测试工具使用,网站上线前压力测试工具. ad测试工具

  9. Apache JMeter 做接口并发测试

    获知来源:查找如何使用Postman进行接口并发测试时,在StackOverflow上看到,说postman只能做串行测试,而且postman并不是被设计做这种测试的:而jmeter就是为了测试而开发 ...

随机推荐

  1. weex踩坑之旅第一弹 ~ 搭建具有入口文件的weex脚手架

    写在前面的话: weex官方文档不完善,在整个实施过程中遇到过很多坑,中途几次想放弃,总是有些不甘心.攻坚克难,总也是会有一些收获,先将收获进行分享也或是记录,防止忘记.要想用好weex必须对es5/ ...

  2. Hibernate数据库的操作

    参考网址: https://www.cnblogs.com/jack1995/p/6952704.html 1.最简单的查询 List<Special> specials = (List& ...

  3. 微信iOS端无法执行jquery on()方法

    微信iOS端无法执行jquery on()方法,click方法可以, 如下代码是不会执行的: $(function(){ $('body').on('click','.cka',function(){ ...

  4. Merge更新同步一个表

    merge T2   --目标表using T1    --源表 on T1.id=T2.id   --匹配条件 when matched then    --匹配update set [name]= ...

  5. 常用工具使用(sublimeText)

    1.sublime Text  (插件的安装,删除,更新) 1.1 使用 ctrl+`快捷键(Esc下面的波浪线按钮) 或者 菜单项View > Show Console 来调出命令界面,下面代 ...

  6. IOS UIView动画(封装动画)

    ● UIKit直接将动画集成到UIView类中,当内部的一些属性发生改变时,UIView 将为这些改变提供动画支持 ● 执行动画所需要的工作由UIView类自动完成,但仍要在希望执行动画时通知视 图, ...

  7. ubuntu or centos 网卡无法启动

    [root@seasoned-bro:/home/daeh0f]# /etc/init.d/network restart Restarting network (via systemctl): Jo ...

  8. 完全用 Linux 工作

    GNU/Linux 不是每個人都想用的.如果你只需要處理一般的事務,玩遊戲,那就不需要了解 Linux. UNIX 比 Windows 更適合用於科學研究工作. 大多數科學家和工程師以 UNIX 作為 ...

  9. 生成.m文件的python代码中出现的错误

    错误代码 import tempfile import subprocess import shlex import os import numpy as np import scipy.io scr ...

  10. PAT (Advanced Level) Practise - 1093. Count PAT's (25)

    http://www.patest.cn/contests/pat-a-practise/1093 The string APPAPT contains two PAT's as substrings ...