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);
即可解决上面的异常问题