使用Unirest通信后,一直打印Closing connections idle longer than 30 SECONDS

 14:05:25,954 INFO  [STDOUT] [PoolingHttpClientConnectionManager] : Closing expired connections
 14:05:25,954 INFO  [STDOUT] [PoolingHttpClientConnectionManager] : Closing connections idle longer than 30 SECONDS
 14:05:26,529 INFO  [STDOUT] [PoolingHttpClientConnectionManager] : Closing expired connections
 14:05:26,529 INFO  [STDOUT] [PoolingHttpClientConnectionManager] : Closing connections idle longer than 30 SECONDS
 14:05:26,826 INFO  [STDOUT] [PoolingHttpClientConnectionManager] : Closing expired connections
 14:05:26,826 INFO  [STDOUT] [PoolingHttpClientConnectionManager] : Closing connections idle longer than 30 SECONDS
 14:05:26,835 INFO  [STDOUT] [PoolingHttpClientConnectionManager] : Closing expired connections
 14:05:26,835 INFO  [STDOUT] [PoolingHttpClientConnectionManager] : Closing connections idle longer than 30 SECONDS

 出现这种情况有两种解决方法,一种是调用shutdown()方法,另一种是修改日志。

Unirest.shutdown();
//在 log4j.xml 里面配置如下一段代码

    
    

第一种方法还是有点问题的,调用该方法后,如果重新执行使用Unirest进行通信,则会报异常:“java.lang.IllegalStateException: Connection pool shut down“。

查看Unirest说明文档(Documentation - Unirest in Java: Simplified, lightweight HTTP client library.)。有该方法的解释,大致意思应该是调用shutdown后,想要再次使用Unirest,需要重新初始化一下,就是rerun一下项目。至此问题大致解决。

使用Unirest通信后,一直打印Closing connections idle longer than 30 SECONDS_第1张图片

但是每次执行一次含有shutdown的方法就要重启一下项目挺麻烦的,这里有另外一个方法 ,即重启Unirest。

com.mashape.unirest.http.options.Options.refresh();

 参考:Server Log in java using Unirest - Stack Overflow

”https://stackoverflow.com/questions/30884851/server-log-in-java-using-unirest“

你可能感兴趣的:(开发语言,java,log4j)