ÃֽŠ°Ô½Ã±Û(JAVA)
2017.07.05 / 02:19

HttpClient - connection still allocated ¿À·ù ÇØ°á ¹æ¹ý

Ŭ·¡½Ä·Î¾â
Ãßõ ¼ö 192

HttpClient ¸¦ »ç¿ëÁß ¾Æ·¡¿Í °°Àº ¿À·ù°¡ ¹ß»ý ÇÑ´Ù.


W/SingleClientConnManager(22006): Invalid use of SingleClientConnManager: connection still allocated


¶Ç´Â



Exception in thread java.lang.IllegalStateException: Invalid use of SingleClientConnManager: connection still allocated.

Make sure to release the connection before allocating another one.



¿¬°áÁß¿¡ ¾ÛÀÌ Á¾·á?ç´Ù´ø°? ¿©Â÷ÀúÂ÷ ±âÁ¸ HttpClient°¡ ÇÒ´çµÇ¾îÀÖÀ»¶§ ¹ß»ýÇÑ´Ù..

±×·¡¼­ HttpClient¸¦ »õ·Ó°Ô ÇÒ´çÇÏ´Â ºÎºÐÀ» ¹Ù²ãÁÖ¾î¾ßÇÑ´Ù..


¾Æ·¡ ÇÔ¼ö¸¦ ÀÌ¿ëÇÑ´Ù.


public static DefaultHttpClient getThreadSafeClient()  {

        DefaultHttpClient client = new DefaultHttpClient();
        ClientConnectionManager mgr = client.getConnectionManager();
        HttpParams params = client.getParams();
        client = new DefaultHttpClient(new ThreadSafeClientConnManager(params, 

                mgr.getSchemeRegistry()), params);
        return client;
}


º¸Åë HttpClient = New DefaultHttpClient(); ó·³ Client¸¦ »õ·Î ÇÒ´çÇØÁÖ´Â ºÎºÐÀ»


httpclient = getThreadSafeClient(); ·Î ¹Ù²Ù¾îÁÖ¸é ÀÌ¹Ì ÇÒ´çµÇ¾î ÀÖÀ¸¸é ÇÒ´çµÈ Client¸¦ ¹ÝȯÇØ ÀÌÈÄ¿¡ ¹®Á¦´Â ¹ß»ýÇÏÁö ¾Ê½À´Ï´Ù.





À§ getThreadSafeClientÇÔ¼ö´Â http://foo.jasonhudgins.com/2010/03/http-connections-revisited.html¿¡¼­ ¹ßÃéÇÏ¿´½À´Ï´Ù.