并发测试 JavaDemo
| /** | |
| * @author Jerry Lee | |
| */ | |
| public class Testee { | |
| static long countTimeIn500ms = 0; | |
| public static void main(String[] args) throws Exception { | |
| countTimeIn500ms = guessCountTimeIn500ms(); | |
| Thread runAndSleepTask = new Thread(new RunAndSleepTask(), "RunAndSleepTask"); | |
| Thread runAndWaitTask = new Thread(new RunAndWaitTask(), "RunAndWaitTask"); | |
| Thread runAndLongSleepTask = new Thread(new RunAndLongSleepTask(), "RunAndLongSleepTask"); | |
| runAndSleepTask.start(); | |
| runAndWaitTask.start(); | |
| runAndLongSleepTask.start(); | |
| System.out.println("Tasks started!"); | |
| Thread.sleep(Long.MAX_VALUE); | |
| } | |
| public static class RunAndSleepTask implements Runnable { | |
| @Override | |
| public void run() { | |
| String name = this.getClass().getSimpleName(); | |
| while (true) { | |
| for (long i = 0; i < countTimeIn500ms; i++) { | |
| } | |
| System.out.println(name + ": " + new Date()); | |
| try { | |
| Thread.sleep(500); | |
| } catch (InterruptedException e) { | |
| e.printStackTrace(); | |
| } | |
| } | |
| } | |
| } | |
| public static class RunAndWaitTask implements Runnable { | |
| @Override | |
| public void run() { | |
| String name = this.getClass().getSimpleName(); | |
| while (true) { | |
| for (long i = 0; i < countTimeIn500ms; i++) { | |
| } | |
| try { | |
| System.out.println(name + ": " + new Date()); | |
| synchronized (this) { | |
| this.wait(500); | |
| } | |
| } catch (InterruptedException e) { | |
| e.printStackTrace(); | |
| } | |
| } | |
| } | |
| } | |
| public static class RunAndLongSleepTask implements Runnable { | |
| @Override | |
| public void run() { | |
| String name = this.getClass().getSimpleName(); | |
| while (true) { | |
| for (long i = 0; i < countTimeIn500ms; i++) { | |
| } | |
| System.out.println(name + ": " + new Date()); | |
| try { | |
| Thread.sleep(5000); | |
| } catch (InterruptedException e) { | |
| e.printStackTrace(); | |
| } | |
| } | |
| } | |
| } | |
| /** | |
| * @return 100ms可以做{@code long}的计数次数。 | |
| */ | |
| static long guessCountTimeIn500ms() { | |
| System.out.println("start guess."); | |
| long count = 1000L * 1000 * 1000; | |
| // simple warm-up | |
| for (long i = 0; i < count; i++) { | |
| // nothing! | |
| } | |
| long tick = System.currentTimeMillis(); | |
| for (long i = 0; i < count; i++) { | |
| // nothing! | |
| } | |
| long duration = System.currentTimeMillis() - tick; | |
| System.out.printf("1G times count take %d ms.\n", duration); | |
| return count * 500 / duration; | |
| } | |
| } |
并发测试 JavaDemo的更多相关文章
- Atitit.并发测试解决方案(2) -----获取随机数据库记录 随机抽取数据 随机排序 原理and实现
Atitit.并发测试解决方案(2) -----获取随机数据库记录 随机抽取数据 随机排序 1. 应用场景 1 2. 随机抽取数据原理 1 3. 常用的实现方法:::数据库随机函数 1 4. Mssq ...
- appium 并发测试
Android并发测试 Appium提供了在一台设备上启动多个Android会话的方案,而这个方案需要你输入不同的指令来启动多个Appium服务来实现. 启动多个Android会话的重要指令包括: - ...
- Fiddler 接口测试(Composer)的使用方法及并发测试
下载地址:https://www.telerik.com/download/fiddler 一.Composer简介 右侧Composer区域,是测试接口的界面: 相关说明: 1.请求方式:点开可以勾 ...
- spring boot2.0.4集成druid,用jmeter并发测试工具调用接口,druid查看监控的结果
一.项目介绍(本项目用的编程语言是jdk8,项目源码:https://github.com/zhzhair/spring-boot-druid.git) 1.引入pom依赖: <dependen ...
- 使用postman进行并发测试
1.打开postman软件 左侧栏点击+号键,创建一个并发测试文件夹 2.主面板点击+号键,输入一个测试地址,点击save按钮保存到并发测试文件夹 3.点击三角箭头,再点击Run,弹出Collecti ...
- Jmeter对HTTP请求压力测试、并发测试的简单使用方法
对于服务器性能测试这块的经验更是少得可以忽略.迫使不得不让我们去尝试了解测试的知识. 首先我们的需求场景如下: 服务器硬件:(只有一台) 系统:Windows 2003 WebServer:Tomca ...
- 协议并发测试工具 BoHexTest
BoHexTest V1.0.3 1.添加连接LOG打印2.优化代理及并发策略 大小: 1074688 字节修改时间: 2017年10月3日, 10:24:26MD5: EBAE5A17F7F5ED0 ...
- SoapUI 利用SoapUI进行简单的接口并发测试
利用SoapUI进行简单的接口并发测试 by:授客 QQ:1033553122 测试环境: SoapUI Pro 5.1.2 步骤如下 1. 把请求添加到测试套件 1.1. 途径1 1.新 ...
- Java接口多线程并发测试 (一)
本文为作者原创,禁止转载,违者必究法律责任!!! 本文为作者原创,禁止转载,违者必究法律责任!!! Java接口多线程并发测试 一,首先写一个接口post 请求代码: import org.apach ...
随机推荐
- linux发送邮件的功能总结
今天添加了发送邮件的功能,总结一下,供以后参考: 1.直接使用管道发送邮件 echo "hello,this is the content of mail.welcome to www.mz ...
- JMX入门开发
什么是JMX?或者是JMX是做什么的?我的理解是:可以远程管理/编辑JAVA对象.如图: 上面的SchemaName属性就是可以动态修改的,那么是如何做到的哪?下面咱们逐步分析. 一.首先假设咱们有个 ...
- SpringBoot使用Mybatis注解进行一对多和多对多查询(2)
SpringBoot使用Mybatis注解进行一对多和多对多查询 GitHub的完整示例项目地址kingboy-springboot-data 一.模拟的业务查询 系统中的用户user都有唯一对应的地 ...
- python知识合集
python安装包管理 http://www.cnblogs.com/wilber2013/p/4769467.html python pip安装源管理:pypi官网的源不太好,网速慢,容易造成包下 ...
- SLF4J warning or error messages and their meanings
来自:http://www.slf4j.org/codes.html#StaticLoggerBinder The method o.a.commons.logging.impl.SLF4FLogFa ...
- Android学习笔记十:异步处理
转载请注明原文地址:http://www.cnblogs.com/ygj0930/p/7520700.html 一:基础概念 UI线程:当Android程序第一次启动时,Android会同时启动一条主 ...
- JSON语言规范与Java中两种解析工具基本使用
转载请注明原文地址:http://www.cnblogs.com/ygj0930/p/6652250.html 一:JSON语言规范 一言以蔽之:“一个 :一个键值对,一个{}一个对象,一个[]一个 ...
- 修改Ubuntu默认运行级别,启动字符界面
Ubuntu的默认开机的runlevel是2,可以用runlevel来查看当前的默认运行级别. debian系(ubuntu是基于debian)的Linux一直是用runlevel 2来默认启动,并且 ...
- FTP在CentOS上安装与使用
安装: yum install -y vsftpd 相关配置文件: /etc/vsftpd/vsftpd.conf //主配置文件,核心配置文件 /etc/vsftpd/ftpusers //黑名单, ...
- 使用Oracle Data Integrator Studio创建资料档案库
一.Creating the Database Schema /*第1步:创建临时表空间 */ create temporary tablespace user_temp tempfile 'C:\a ...