|
From: Guy R. <guy...@gm...> - 2014-05-28 04:49:19
|
The RESTEasy documentation specifically says (section 48.3): "Finally, if your javax.ws.rs.client.Client class has created the engine automatically for you, you should call Client.close() and this will clean up any socket connections." Yet the overwhelming majority of examples I can find, including those shipped with RESTEasy, do not explicitly invoke Client.close(). Is this because resource cleanup will eventually be done automatically during garbage collection? We are using the ResteasyClient proxy approach, but that class extends Client, so I'm assuming the same discussion holds for the proxy. Thanks. -- Guy Rouillier --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com |
|
From: Bill B. <bb...@re...> - 2014-05-28 12:06:21
|
The examples are bad examples of clean code. On 5/28/2014 12:49 AM, Guy Rouillier wrote: > The RESTEasy documentation specifically says (section 48.3): > > "Finally, if your javax.ws.rs.client.Client class has created the engine > automatically for you, you should call Client.close() and this will > clean up any socket connections." > > Yet the overwhelming majority of examples I can find, including those > shipped with RESTEasy, do not explicitly invoke Client.close(). Is this > because resource cleanup will eventually be done automatically during > garbage collection? > > We are using the ResteasyClient proxy approach, but that class extends > Client, so I'm assuming the same discussion holds for the proxy. > > Thanks. > -- Bill Burke JBoss, a division of Red Hat http://bill.burkecentral.com |
|
From: Bill B. <bb...@re...> - 2014-05-28 12:06:52
|
Oh, one more thing. ResteasyClient does implement finalize and will close during garbage collection. On 5/28/2014 12:49 AM, Guy Rouillier wrote: > The RESTEasy documentation specifically says (section 48.3): > > "Finally, if your javax.ws.rs.client.Client class has created the engine > automatically for you, you should call Client.close() and this will > clean up any socket connections." > > Yet the overwhelming majority of examples I can find, including those > shipped with RESTEasy, do not explicitly invoke Client.close(). Is this > because resource cleanup will eventually be done automatically during > garbage collection? > > We are using the ResteasyClient proxy approach, but that class extends > Client, so I'm assuming the same discussion holds for the proxy. > > Thanks. > -- Bill Burke JBoss, a division of Red Hat http://bill.burkecentral.com |
|
From: Guy R. <guy...@gm...> - 2014-05-28 21:16:47
|
Thanks for the reply, Bill. I cloned the RESTEasy repo so I could look at the latest source. I see that ResteasyClient.java has a close() method, but no finalize(). So, I suppose the most conservative course of action would be to specifically invoke ResteasyClient.close() in a finally block for any code that creates an instance. On 5/28/2014 8:06 AM, Bill Burke wrote: > Oh, one more thing. ResteasyClient does implement finalize and will > close during garbage collection. > > On 5/28/2014 12:49 AM, Guy Rouillier wrote: >> The RESTEasy documentation specifically says (section 48.3): >> >> "Finally, if your javax.ws.rs.client.Client class has created the engine >> automatically for you, you should call Client.close() and this will >> clean up any socket connections." >> >> Yet the overwhelming majority of examples I can find, including those >> shipped with RESTEasy, do not explicitly invoke Client.close(). Is this >> because resource cleanup will eventually be done automatically during >> garbage collection? >> >> We are using the ResteasyClient proxy approach, but that class extends >> Client, so I'm assuming the same discussion holds for the proxy. >> >> Thanks. >> > -- Guy Rouillier --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com |
|
From: Bill B. <bb...@re...> - 2014-05-29 12:27:06
|
THere is a finalize in ApacheHttpClient4Engine. We actually have a unit test that tests GC for responses and clients. But, you should never rely on finalize. Its really bad practice. The examples are a poor job on my end if they don't do close. On 5/28/2014 5:16 PM, Guy Rouillier wrote: > Thanks for the reply, Bill. I cloned the RESTEasy repo so I could look > at the latest source. I see that ResteasyClient.java has a close() > method, but no finalize(). So, I suppose the most conservative course > of action would be to specifically invoke ResteasyClient.close() in a > finally block for any code that creates an instance. > > On 5/28/2014 8:06 AM, Bill Burke wrote: >> Oh, one more thing. ResteasyClient does implement finalize and will >> close during garbage collection. >> >> On 5/28/2014 12:49 AM, Guy Rouillier wrote: >>> The RESTEasy documentation specifically says (section 48.3): >>> >>> "Finally, if your javax.ws.rs.client.Client class has created the engine >>> automatically for you, you should call Client.close() and this will >>> clean up any socket connections." >>> >>> Yet the overwhelming majority of examples I can find, including those >>> shipped with RESTEasy, do not explicitly invoke Client.close(). Is this >>> because resource cleanup will eventually be done automatically during >>> garbage collection? >>> >>> We are using the ResteasyClient proxy approach, but that class extends >>> Client, so I'm assuming the same discussion holds for the proxy. >>> >>> Thanks. >>> >> > > -- Bill Burke JBoss, a division of Red Hat http://bill.burkecentral.com |