分布式系统测试?使用HttpServer的一个并发问题
作者:网络转载 发布时间:[ 2014/2/28 10:21:22 ] 推荐标签:系统测试 分布式 并发
public void run() {
Random rd = new Random();
int index = rd.nextInt(60);
if (index < 10){
index = index + 10;
}
String indexStr = Integer.toString(index);
String path = indexStr+”-”+indexStr+”-”+indexStr+”/”;
LogGetter logGetter = new LogGetter();
logGetter.setPath(path);
String runningLog = logGetter.getRunningLog(0L);
if(runningLog.contains( “T3_000000000″ + indexStr)){
System.out.println(“==============>”+”exit”);
}else
{
String[] lines = runningLog.split(“ ”);
System.out.println(“期望:” + indexStr + “ ” + “实际请求的:” + lines[0] + “ ”);
}
}
}
}
定位到问题之后,我们决定放弃使用这个方法,自己重写一个parserQuery的方法,后台拿到url之后重新对url进行参数的解析。
Map params = HttpUtils.parseQuery(httpExchange.getRequestURI().getQuery());
public static Map parserQuery(String query) throws UnsupportedEncodingException {
Map parameters = new HashMap();
if (query != null) {
String pairs[] = query.split(“[&]“);
for (String pair : pairs) {
String param[] = pair.split(“[=]“);
String key = null;
String value = null;
if (param.length > 0) {
key = URLDecoder.decode(param[0], System.getProperty(“file.encoding”));
}
if (param.length > 1) {
value = URLDecoder.decode(param[1], System.getProperty(“file.encoding”));
}
parameters.put(key, value);
}
}
return parameters;
}
使用了新的params之后,重新使用1000并发,发10000,50000请求,都无法再出现类似的问题,该问题得到解决。

sales@spasvo.com