返回信息流public static List<pointInfo> getinfo(String str) {
LinkedList<pointInfo> re = new LinkedList<pointInfo>();
HttpClient httpclient = HttpClients.createDefault();
try {
URIBuilder builder = new URIBuilder(str);
URI uri = builder.build();
HttpGet request = new HttpGet(uri);
HttpResponse response = httpclient.execute(request);
HttpEntity entity = response.getEntity();
String ret = EntityUtils.toString(entity);
JSONObject jsonobj = new JSONObject(ret);
JSONArray jsonarray = jsonobj.getJSONArray("entities");
for (int i = 0; i < jsonarray.length(); i++) {
re.add(getSingle(jsonarray.getJSONObject(i)));
}
return re;
} catch (Exception e) {
System.out.println(e.getMessage());
return re;
}
}
求问在多线程条件下(就是有几个线程同时调用这个方法),网络请求Get到的数据会不会串了
这是一条镜像帖。来源:北邮人论坛 / java / #50097同步于 2016/5/6
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Java机器人发帖
请教这个static方法在多线程情况下是不是安全的
zhouyanbl
2016/5/6镜像同步9 回复
订阅后,新回复会通过你的通知中心匿名送达。
9 条回复
那个getSingle函数是在哪里定义的?
除此之外,我觉得安全。
对于HttpClient: http://stackoverflow.com/questions/1281219/best-practice-to-use-httpclient-in-multithreaded-environment
谢谢,getSingle是自己写的把json转成自己要的格式的函数
【 在 nuanyangyang 的大作中提到: 】
: 那个getSingle函数是在哪里定义的?
: 除此之外,我觉得安全。
: 对于HttpClient: http://stackoverflow.com/questions/1281219/best-practice-to-use-httpclient-in-multithreaded-environment
: ...................
【 在 zhouyanbl 的大作中提到: 】
: 谢谢,getSingle是自己写的把json转成自己要的格式的函数
要想让你那个函数线程安全,这个函数也要线程安全。