压力测试时,利用Java让CPU使用率达到100%
2013-10-01 21:14
519 查看
如果你还没达到100%,增加下面的for循环次数。
import java.io.IOException; public class CPUTest { public static void main(String[] args) { CPUTestThread cpuTestThread = new CPUTestThread(); for (int i = 0; i < 3; i++) { Thread cpuTest = new Thread(cpuTestThread); cpuTest.start(); } //Windows Task Manager shows try { Runtime.getRuntime().exec("taskmgr"); } catch (IOException e1) { e1.printStackTrace(); } } } class CPUTestThread implements Runnable { @Override public void run() { int busyTime = 10; int idleTime = busyTime; long startTime = 0; while (true) { startTime = System.currentTimeMillis(); System.out.println(System.currentTimeMillis()+","+startTime+","+(System.currentTimeMillis() - startTime)); // busy loop while ((System.currentTimeMillis() - startTime) <= busyTime) ; // idle loop try { Thread.sleep(idleTime); } catch (InterruptedException e) { System.out.println(e); } } } }
相关文章推荐
- 循环使用正则导致进程挂起和CPU使用率达到100%居高不下测试Demo
- java urlrewrite 正则不当导致压力测试时CPU持续100%
- 利用TPTP对Java程序进行性能测试
- 利用JMeter进行压力测试(3)
- Java模拟并发操作进行压力测试代码
- RabbitMQ/JAVA 客户端测试(补:利用线程)
- 利用JMeter进行压力测试(1)
- 利用jmeter+JAVA对RPC的单接口(dubbo接口等)进行性能测试,零基础(2)
- java服务端程序部署服务器以及压力测试过程
- java版 贪吃蛇小游戏 完整源码 (测试100%无误
- JAVA使用Microsoft Web Application Stress Tool对web进行压力测试
- 【JAVA秒会技术之压力测试工具】JMeter在电商开发中的简单应用
- RABBITMQ/JAVA 客户端测试(再补:利用文件流)
- 利用tcpcopy 做压力测试
- SuperMap iServerJava 6R扩展领域开发及压力测试---判断点在那个面内(1)
- 利用wsdl文件生成webservice接口的java客户端测试代码
- 利用压力测试来保证软件的质量(九) 访问违例问题
- Jmeter压力测试-自定义java请求
- Java项目通过JMeter进行压力测试
- 压力测试下的java内存回收优化