Java 正确使用Restlet ClientResource

Java 正确使用Restlet ClientResource,java,apache,httpclient,restlet,Java,Apache,Httpclient,Restlet,我在Restlet(v2.0.5)中遇到了一个ClientResource问题,这可能是因为不理解它的正确用法 我正在使用ClientResource和Apache HTTP客户端连接器,并编写了以下内容: private final ClientResource httpClient; public SendClient(String uri) { httpClient = new ClientResource(uri);

我在Restlet(v2.0.5)中遇到了一个ClientResource问题,这可能是因为不理解它的正确用法

我正在使用ClientResource和Apache HTTP客户端连接器,并编写了以下内容:

        private final ClientResource httpClient;
        public SendClient(String uri) {
            httpClient = new ClientResource(uri);
        }
        // Omitted code would create messages to send, and then use an executor
        // to send this particular message to its destination.
        public void run() {
           ClientResource sendClient = null;
           try {
              sendClient = wsClient.getChild(uriResource); // re-use original httpclient instance, uriResource is passed in to the method that calls this.
              sendClient.post(form);
           } catch (Throwable e) {
              logger.error("Unable to send message, {}", e.getMessage());
           } finally {
              if (sendClient != null) {
                 sendClient.release(); // As I understand from [Restlet WIKI][1] 
              }
           }
        }
这是正确的吗?我怀疑不是这样,因为在几个小时(7个或更多)后,这段代码开始抛出以下错误,“内部服务器错误”,并且目标不再接收消息

你知道我做错了什么吗

请注意,我知道ClientResource不是线程安全的,您会注意到,在我的代码中,我使用了一个执行器来运行这段代码,但是,该执行器只包含一个线程,因此,在我了解其他情况之前,我排除了这一问题

注释2:Client资源JavaDoc表示:“并发注解:类的实例不是被设计成在多个线程之间共享的。如果线程安全是必要的,考虑使用较低级别的客户端类来代替。”然而,RestLee创建者说,实际上它是线程安全的,而不是为这个目的而显式设计的。


谢谢。

ClientResource是线程安全的,但它不是专门为多个并发线程设计的,即使它是可能的。但是,多次重用同一实例是完全有效的

回到您的问题,我们需要更详细的问题堆栈跟踪来帮助解决,因为“内部服务器错误”会导致服务器端而不是客户端出现问题

希望这有帮助, 杰罗姆