RESTEasy客户端代理开销?

我正在使用客户端代理创建一个RESTEasy服务,它到目前为止工作正常。 但是,我确实注意到在我的一些函数中,我看到了相同的代码行:

MyClass client = ProxyFactory.create(MyClass.class, "http://localhost:8080"); 

从函数中取出它并使其成为类的成员变量以减少可能的开销是否更好? 此服务将处理10000 reqs / min的负载。 谢谢

例如,您可以将MyClass客户端指定为spring bean,并将其注入任何需要的位置。 请注意线程安全,因为RestEasy代理客户端在Apache Commons Http Client下使用,默认情况下使用非线程安全的SimpleHttpConnectionManager。

要在multithreading环境中运行(在Servlet容器中运行),请执行以下操作:

 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);