Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #37555
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Java 9 issues |
| Date | 2017-10-04 11:20 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <or2u83$jk2$1@dont-email.me> (permalink) |
| References | <3932fb50-27ec-475c-9e74-45387ba59ac1@googlegroups.com> <fa039415-999b-4a40-9943-422a3ee2495b@googlegroups.com> <or0vtk$bcn$1@dont-email.me> <fa3d490a-9119-48b4-92f8-048ac7107be3@googlegroups.com> |
On 10/4/2017 10:51 AM, Eric Douglas wrote:
> On Tuesday, October 3, 2017 at 5:37:00 PM UTC-4, Eric Sosman wrote:
>>
>> It seems you may have been abusing finalize() as a destructor. That
>> is and always has been bad practice. Quoth Bloch in "Effective Java:"
>
> I do have a proper terminate method which is supposed to be calling before destroying the instance. I was just hoping it was possible to implement a failsafe to close a resource instance such as this watcher service or a socket listener which is supposed to remain open for the life of the object.
Ah! Okay, that's reasonable -- finalize() as a fail-safe,
rather than as a destructor substitute.
If you still want the fail-safe, I can think of two likely
approaches:
- Keep on using finalize() as you have been, and ignore
the deprecation warnings.
- (Haven't tried this myself): Ditch finalize(), create a
Reference to your object, and register the Reference with
a ReferenceQueue. When the queue notifies you that the
object is no longer reachable, you can then check that
it's been properly closed.
--
esosman@comcast-dot-net.invalid
Twelve hundred four days to go.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Java 9 issues Eric Douglas <e.d.programmer@gmail.com> - 2017-10-03 08:12 -0700
Re: Java 9 issues Arne Vajhøj <arne@vajhoej.dk> - 2017-10-03 11:33 -0400
Re: Java 9 issues Patrick Roemer <sangamon@netcologne.de> - 2017-10-03 17:43 +0200
Re: Java 9 issues Arne Vajhøj <arne@vajhoej.dk> - 2017-10-03 12:07 -0400
Re: Java 9 issues Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2017-10-03 11:20 -0500
Re: Java 9 issues Eric Douglas <e.d.programmer@gmail.com> - 2017-10-03 10:19 -0700
Re: Java 9 issues Arne Vajhøj <arne@vajhoej.dk> - 2017-10-03 14:10 -0400
Re: Java 9 issues Patrick Roemer <sangamon@netcologne.de> - 2017-10-03 20:20 +0200
Re: Java 9 issues Arne Vajhøj <arne@vajhoej.dk> - 2017-10-03 15:37 -0400
Re: Java 9 issues Eric Douglas <e.d.programmer@gmail.com> - 2017-10-03 12:52 -0700
Re: Java 9 issues Patrick Roemer <sangamon@netcologne.de> - 2017-10-03 22:27 +0200
Re: Java 9 issues Eric Douglas <e.d.programmer@gmail.com> - 2017-10-03 13:38 -0700
Re: Java 9 issues Patrick Roemer <sangamon@netcologne.de> - 2017-10-03 22:55 +0200
Re: Java 9 issues Arne Vajhøj <arne@vajhoej.dk> - 2017-10-03 19:45 -0400
Re: Java 9 issues Eric Douglas <e.d.programmer@gmail.com> - 2017-10-04 05:18 -0700
Re: Java 9 issues Arne Vajhøj <arne@vajhoej.dk> - 2017-10-04 20:04 -0400
Re: Java 9 issues Eric Douglas <e.d.programmer@gmail.com> - 2017-10-05 06:10 -0700
Re: Java 9 issues Martin Gregorie <martin@address-in-sig.invalid> - 2017-10-05 11:06 +0000
Re: Java 9 issues Eric Douglas <e.d.programmer@gmail.com> - 2017-10-05 06:09 -0700
Re: Java 9 issues Martin Gregorie <martin@address-in-sig.invalid> - 2017-10-05 18:23 +0000
Re: Java 9 issues Eric Douglas <e.d.programmer@gmail.com> - 2017-10-03 12:03 -0700
Re: Java 9 issues Eric Douglas <e.d.programmer@gmail.com> - 2017-10-03 13:34 -0700
Re: Java 9 issues Eric Douglas <e.d.programmer@gmail.com> - 2017-10-03 13:49 -0700
Re: Java 9 issues Arne Vajhøj <arne@vajhoej.dk> - 2017-10-03 19:39 -0400
Re: Java 9 issues Eric Douglas <e.d.programmer@gmail.com> - 2017-10-03 14:01 -0700
Re: Java 9 issues Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-10-03 17:36 -0400
Re: Java 9 issues Eric Douglas <e.d.programmer@gmail.com> - 2017-10-04 07:51 -0700
Re: Java 9 issues Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-10-04 11:20 -0400
Re: Java 9 issues v_borchert@despammed.com (Volker Borchert) - 2017-10-04 20:14 +0000
Re: Java 9 issues Arne Vajhøj <arne@vajhoej.dk> - 2017-10-03 19:23 -0400
csiph-web