多进程多组建性能测试

来源:互联网 发布:智能手表软件下载 编辑:程序博客网 时间:2024/06/18 05:47
package org.cmm.thread;


import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;


public class TwoThread {


public String processcall2() throws Exception{
// 设置线程数量
ExecutorService pool = Executors.newFixedThreadPool(500);
// 不限制线程数量
// ExecutorService pool = Executors.newCachedThreadPool();
// 任务数量
for (int i = 0; i < 25000000; i++) {
Runnable r = new Runnable() {
public void run() {
int x = 0;
for(int i = 0; i < 500; i++){
x += i;
if(x > 500){
x -= 500;
}
}
// System.out.println(x);
}
};
pool.execute(r);
}
pool.shutdown();
return "";
}

public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
Long loa = System.currentTimeMillis();
TwoThread ot = new TwoThread();
ot.processcall2();
Long lob = System.currentTimeMillis();
Long lo = lob - loa;
System.out.println(lo);
}


}






批处理:@echo off -jar (java文件打成JAR包的路径)  pause