Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Eric Sosman Newsgroups: comp.lang.java.programmer Subject: Re: Java 9 issues Date: Tue, 3 Oct 2017 17:36:49 -0400 Organization: A noiseless patient Spider Lines: 27 Message-ID: References: <3932fb50-27ec-475c-9e74-45387ba59ac1@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Tue, 3 Oct 2017 21:36:52 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="30b67282d449da050462885190ea06b8"; logging-data="11671"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX191VSfZhBdwW54RmeMn2Q5J" User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 In-Reply-To: X-Antivirus-Status: Clean Content-Language: en-US X-Antivirus: AVG (VPS 171003-2, 10/03/2017), Outbound message Cancel-Lock: sha1:gJkSfl5cfhfR4VUCOymdcSbYqR4= Xref: csiph.com comp.lang.java.programmer:37546 On 10/3/2017 4:34 PM, Eric Douglas wrote: > On Tuesday, October 3, 2017 at 11:12:18 AM UTC-4, Eric Douglas wrote: >> Then there's the next trivial issue of all the now deprecated methods I'm referencing. >> [...] >> Object.finalize() > *** this is the tricky one *** > > So, what to do with finalize()?? Oracle's comment block on this one simply says it's deprecated, as in the don't know how to properly execute it and just want to do away with it. In this case I have a file watcher class, using java.nio.file.WatchService in a daemon thread, and want to close it properly.. It seems you may have been abusing finalize() as a destructor. That is and always has been bad practice. Quoth Bloch in "Effective Java:" Item 6: Avoid finalizers [...] C++ programmers are cautioned not to think of finalizers as the analog of C++ destructors. [...] So what should you do instead of writing a finalizer for a class whose objects encapsulate resources that require termination, such as files or threads? Just provide an explicit termination method, and require clients of the class to invoke this method on each instance when it is no longer needed. [...] Don't try to resuscitate bad practice; reform it. -- esosman@comcast-dot-net.invalid Twelve hundred five days to go.