fastjson toJSONString 多线程高并发下耗时长

vc6uscn9  于 2021-11-27  发布在  Java
关注(0)|答案(0)|浏览(549)

code:

@slf4j
public class TestFastJson {
public static void main(String[] args) throws Exception {
Scanner s = new Scanner(System.in);
System.out.println("请输入字符串:");
while (true) {
String line = s.nextLine();
if (line.equals("exit")) {
break;
}
System.out.println(">>>" + line);
// LogFilter.setFilterField(Lists.newArrayList("gmtModified", "geoHash"));
String test =
"[{"gmtModified":1632705494321,"geoHash":"wtmk","temperatureMax":31.00,"windLevel":"4-5","windDir":"东","type":1,"no2":"43.0","apparentTemperatureMin":21.00,"so2":"7.0","humidity":"68","rank":"640/670","id":1355737350,"windSpeed":"8.05","temp":"31","o3":"28.0","pm10":"75.0","temperatureMin":21.00,"uvi":"9","pressure":"","co":"0.7","gmtCreate":1632705494321,"apparentTemperatureMax":31.00,"condition":"晴","pm25":"39.0","aqi":"63","time":1633190400000,"lastUpdateTime":1632701460000},{"gmtModified":1632705494321,"geoHash":"wtmk","temperatureMax":32.00,"windLevel":"3-4","windDir":"东","type":1,"no2":"43.0","apparentTemperatureMin":22.00,"so2":"7.0","humidity":"70","rank":"640/670","id":1355737349,"windSpeed":"5.6","temp":"32","o3":"28.0","pm10":"75.0","temperatureMin":22.00,"uvi":"9","pressure":"","co":"0.7","gmtCreate":1632705494321,"apparentTemperatureMax":32.00,"condition":"晴","pm25":"39.0","aqi":"63","time":1633104000000,"lastUpdateTime":1632701460000}]";
JSONArray jsonArray = JSON.parseArray(test);
for (int i = 0; i < 300; i++) {
new Thread(new Runnable() {
@OverRide
public void run() {
long time = System.currentTimeMillis();
jsonArray.toJSONString();
log.info(" ===============> time:{}", (System.currentTimeMillis() - time));
}
}).start();
}
}

}

}

result print:

2021-10-11 15:49:31.248|TID: N/A|INFO |com.tuya.poicenter.test.TestFastJson|run|36|Thread-103| ===============> time:940
2021-10-11 15:49:31.247|TID: N/A|INFO |com.tuya.poicenter.test.TestFastJson|run|36|Thread-245| ===============> time:998
2021-10-11 15:49:31.250|TID: N/A|INFO |com.tuya.poicenter.test.TestFastJson|run|36|Thread-16| ===============> time:1075
2021-10-11 15:49:31.247|TID: N/A|INFO |com.tuya.poicenter.test.TestFastJson|run|36|Thread-178| ===============> time:1019
2021-10-11 15:49:31.248|TID: N/A|INFO |com.tuya.poicenter.test.TestFastJson|run|36|Thread-175| ===============> time:825
2021-10-11 15:49:31.248|TID: N/A|INFO |com.tuya.poicenter.test.TestFastJson|run|36|Thread-204| ===============> time:1035
2021-10-11 15:49:31.248|TID: N/A|INFO |com.tuya.poicenter.test.TestFastJson|run|36|Thread-54| ===============> time:1078
2021-10-11 15:49:31.248|TID: N/A|INFO |com.tuya.poicenter.test.TestFastJson|run|36|Thread-33| ===============> time:867
2021-10-11 15:49:31.247|TID: N/A|INFO |com.tuya.poicenter.test.TestFastJson|run|36|Thread-46| ===============> time:1065

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题