我有Android应用程序与Web服务器通信。 我的应用程序向Web服务器发送请求并从中获取响应(JSONObject)。
一切都很好,但有一个问题出现了。 垃圾收集器开始狂暴并且每秒运行5-10次并且没有任何东西可以停止。这就是为什么我的另一个线程无法运行
10-22 09:56:35.121: D/dalvikvm(3483): GC_CONCURRENT freed 1920K, 26% free 14517K/19399K, paused 13ms+0ms, total 19ms
10-22 09:56:35.401: D/dalvikvm(3483): GC_CONCURRENT freed 1920K, 26% free 14517K/19399K, paused 20ms+0ms, total 26ms
10-22 09:56:35.661: D/dalvikvm(3483): GC_CONCURRENT freed 1919K, 26% free 14517K/19399K, paused 19ms+1ms, total 25ms
10-22 09:56:35.891: D/dalvikvm(3483): GC_CONCURRENT freed 1919K, 26% free 14517K/19399K, paused 15ms+0ms, total 20ms
10-22 09:56:36.151: D/dalvikvm(3483): GC_CONCURRENT freed 1896K, 26% free 14540K/19399K, paused 16ms+0ms, total 22ms
10-22 09:56:36.431: D/dalvikvm(3483): GC_CONCURRENT freed 1946K, 26% free 14514K/19399K, paused 19ms+0ms, total 25ms
10-22 09:56:36.691: D/dalvikvm(3483): GC_CONCURRENT freed 1920K, 26% free 14514K/19399K, paused 21ms+0ms, total 27ms
10-22 09:56:36.911: D/dalvikvm(3483): GC_CONCURRENT freed 1920K, 26% free 14514K/19399K, paused 13ms+0ms, total 19ms
这是我的代码:
private HttpResponse postWebRequest(String address, List<BasicNameValuePair> params, ArrayList<BasicNameValuePair> headers)
{
HttpResponse response = null;
try
{
DefaultHttpClient client = new DefaultHttpClient();
HttpPost request = new HttpPost(address);
request.setURI(new URI(address));
request.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
if (headers != null)
{
for (int i = 0; i < headers.size(); i++)
{
request.setHeader(headers.get(i).getName(), headers.get(i).getValue());
}
}
response = client.execute(request); // here problem arise!!!
} catch (URISyntaxException e)
{
e.printStackTrace();
} catch (ClientProtocolException e)
{
e.printStackTrace();
e.getMessage();
} catch (IOException e)
{
e.printStackTrace();
}
return response;
}
有人想知道为什么会这样吗? 附:抱歉英语不好=))