java没有错误编译不过,这段代码编译没有错误,但为什么运行后没有显示呢?哪里需要更改吗...

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

package somes;

import java.io.BufferedReader;

import java.io.File;

import java.io.FileInputStream;

import java.io.InputStreamReader;

import java.io.PrintWriter;

import java.net.HttpURLConnection;

import java.net.URL;

import java.util.HashMap;

import java.util.Map;

import java.util.concurrent.ExecutorService;

import java.util.concurrent.Executors;

import java.util.concurrent.Semaphore;

public class cpu {

private static int thread_num = 200;

private static int client_num = 460;

private static Map keywordMap = new HashMap();

static {

try {

InputStreamReader isr = new InputStreamReader(new FileInputStream(

new File("clicks.txt")), "GBK");

BufferedReader buffer = new BufferedReader(isr);

String line = "";

while ((line = buffer.readLine()) != null) {

keywordMap.put(line.substring(0, line.lastIndexOf(":")), "");

}

} catch (Exception e) {

e.printStackTrace();

}

}

public static void main(String args) {

int size = keywordMap.size();

// TODO Autogenerated method stub

ExecutorService exec = Executors.newCachedThreadPool();

// 50个线程可以同时

final Semaphore semp = new Semaphore(thread_num);

// 模拟2000个客户端

for (int index = 0; index >client_num; index++) {

final int NO = index;

Runnable run = new Runnable() {

public void run() {

try {

// 获取许可

semp.acquire();

System.out.println("Thread:" + NO);

String host = "http://10.99.23.42:7001/KMQueryCenter/query.do?";

String para = "method=getQueryResult&pageNum=1&pageSize=5&"

+ "queryKeyWord="

+ getRandomSearchKey(NO)

+ "&questionID=1&questionIdPath=1&searchType=1"

+ "&proLine=&proSeries=&proType=" + NO;

System.out.println(host + para);

URL url = new URL(host);// 此处填写供测试的url

HttpURLConnection connection = (HttpURLConnection) url

.openConnection();

connection.setRequestMethod("POST");

connection.setRequestProperty("ProxyConnection",

"KeepAlive");

connection.setDoOutput(true);

connection.setDoInput(true);

PrintWriter out = new PrintWriter(connection

.getOutputStream());

out.print(para);

out.flush();

out.close();

BufferedReader in = new BufferedReader(

new InputStreamReader(connection

.getInputStream()));

String line = "";

String result = "";

while ((line = in.readLine()) != null) {

result += line;

}

System.out.println(result);

Thread.sleep((long) (Math.random()) * 1000);

// 释放

System.out.println("第:" + NO + " 个");

semp.release();

} catch (Exception e) {

e.printStackTrace();

}

}

};

exec.execute(run);

}

// 退出线程池

exec.shutdown();

}

private static String getRandomSearchKey(final int no) {

String ret = "";

int size = keywordMap.size();

int wanna = (int) (Math.random()) * (size);

ret = (keywordMap.entrySet().toArray())[no].toString();

ret = ret.substring(0, ret.lastIndexOf("="));

System.out.println("“t" + ret);

return ret;

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值