我開發使用ProxyFactory裏和ClientExecutor像這樣的RESTEasy服務:RESTEasy線程中的ProxyFactory替換是否安全?
PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager();
DefaultHttpClient httpClient = new DefaultHttpClient(connectionManager);
HttpParams params = httpClient.getParams();
HttpConnectionParams.setConnectionTimeout(params, 5000);
HttpConnectionParams.setSoTimeout(params, 5000);
ClientExecutor clientExecutor = new ApacheHttpClient4Executor(httpClient);
MyClass client = ProxyFactory.create(MyClass.class, "http://www.example.com", clientExecutor);
它總是完美。在RESTEasy棄用ClientExecutor和ProxyFactory之後,他們提供了一個新的ResteasyClient用於外部連接,但我不知道這個新的ResteasyClient是否是線程安全的。這是從文檔的新樣本代碼:
ResteasyClient client = new ResteasyClientBuilder().build();
ResteasyWebTarget target = client.target("http://example.com/base/uri");
SimpleClient simple = target.proxy(SimpleClient.class);
更新:我用的ResteasyClient的代碼,我得到了許多這樣的錯誤:
javax.ws.rs.ProcessingException: Unable to invoke request
通過
java.lang.IllegalStateException: Invalid use of BasicClientConnManager: connection still allocated. Make sure to release the connection before allocating another one.
引起
運行到同樣的問題。你有沒有找到解決方案? – javatestcase