たとえば、MyClassクライアントをSpring Beanとして指定し、必要な場所に挿入することができます。 RestEasyプロキシクライアントはApache Commons Http Clientの下で使用され、デフォルトではスレッドセーフではないSimpleHttpConnectionManagerが使用されるため、スレッドの安全性に注意してください。
MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
HttpClient httpClient = new HttpClient(connectionManager);
// Only needed if you have a authentication
Credentials credentials = new UsernamePasswordCredentials(username, password);
httpClient.getState().setCredentials(AuthScope.ANY, credentials);
httpClient.getParams().setAuthenticationPreemptive(true);
clientExecutor = new ApacheHttpClientExecutor(httpClient);
MyClass client = ProxyFactory.create(MyClass.class, "http://localhost:8080", clientExecutor);
出典
2013-03-19 19:26:10
emd
ありがとう:マルチスレッドenironmentでこれを達成するために
(サーブレットコンテナで実行されているが)、これを行います!これはコードをスレッドセーフにしますか? – avillagomez
@avillagomez - はい – emd
@avillagomez - MyClassクライアントがシングルトンであることを確認してください(インスタンス化は1回だけです) – emd