I am a still unclear as to the best practice.
In the example you give on the wiki, you call stop() on the resource, and there is no try/catch, but you do not mention whether using stop() is a good idea. In relation to the last paragraph -- my experience has shown that exhaust() is not good enough (Restlet 2.0.x, Apache HTTP Client), and still leads to hanging threads. Even calling release() on the representation is not good enough. I found that the only way to avoid hangs is a complete release() of the *response*, and I found this out only through searching in the mailing list. While this does avoid hanging my application, it seems like this is not recommended. Can you clarify? -Tal On 12/31/2010 03:39 AM, Jerome Louvel wrote: > Hi all, > > I've updated the wiki to clarify this best practice, see the last section: > http://wiki.restlet.org/docs_2.0/285-restlet.html > > The Javadocs have also been previously clarified before, saying that > release() should rarely be called: > http://www.restlet.org/documentation/2.0/jee/api/org/restlet/representation/Representation.html#release%28%29 > > I've clarified this even further in SVN (2.0 and trunk) by adding this > paragraph: > * Note that calling this method will likely prevent the reuse of the > * underlying persistent connection and therefore should only be called > when > * exhausting the content with {...@link #exhaust()} is too costly or > when > * further calls from the client are not welcome. > > Hope this clarifies. We can update the wiki/javadocs further based on your > experienced. If one connector such as Apache HTTP Client 4 doesn't work > consistently with this description, we can try to fix it. > > Best regards, > Jerome > -- > Restlet ~ Founder and Technical Lead ~ http://www.restlet.org > Noelios Technologies ~ http://www.noelios.com > > > > > > -----Message d'origine----- > De : Rickard Öberg [mailto:rickardob...@gmail.com] > Envoyé : vendredi 31 décembre 2010 03:18 > À : discuss@restlet.tigris.org > Objet : Re: response.release() versus response.exhaust() in 2.0 > > On 2010-12-31 05.55, Tal Liron wrote: >> pool.) It's probably best to employ a try-finally paradigm, where the >> try clause contains as little code as possible, and the finally clause >> releases the response. See the example below. >> >> var fixture >> var resource = >> document.external('file:///myfiles/fixture.json','application/json') >> try { >> fixture = resource.get().text >> >> } >> finally { >> resource.response.release() >> } > So this, combined with Jerome's reply: >> >> 1) release() has the effect of closing the underlying TCP >> socket, preventing persistent connection reuse. So it can't be >> recommended to systematically call it. > basically means that we can't have persistent connection reuse on the client. > Correct or not? > > /Rickard > > ------------------------------------------------------ > http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2695100 > > ------------------------------------------------------ > http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2695151 ------------------------------------------------------ http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2695206