您的位置:首页 > 其它

调用rest地址时异常:Invalid use of BasicClientConnManager: connection still allocated.

2015-02-02 11:52 866 查看
Caused by: java.lang.IllegalStateException: Invalid use of BasicClientConnManager: connection still allocated.

Make sure to release the connection before allocating another one.

使用Resteasy进行restful方式调用时出现上面的异常,原因大概是由于HttpClient做多线程rest调用导致。代码是:

RegisterBuiltin.register(ResteasyProviderFactory.getInstance());
yourClassName = ProxyFactory.create(yourClassName.class, url);

改为:

ClientConnectionManager cm = new ThreadSafeClientConnManager();
HttpClient httpClient = new DefaultHttpClient(cm);
ClientExecutor executor = new ApacheHttpClient4Executor(httpClient);
RegisterBuiltin.register(ResteasyProviderFactory.getInstance());
yourClassName = ProxyFactory.create(yourClassName.class, url, executor);
即可解决上面的异常问题
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐