X-Received: by 2002:ae9:ebd4:: with SMTP id b203mr1891102qkg.17.1554488020714; Fri, 05 Apr 2019 11:13:40 -0700 (PDT) X-Received: by 2002:a81:6c04:: with SMTP id h4mr11968505ywc.170.1554488020450; Fri, 05 Apr 2019 11:13:40 -0700 (PDT) Path: csiph.com!weretis.net!feeder6.news.weretis.net!feeder.usenetexpress.com!feeder-in1.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!t9no1799862qtn.0!news-out.google.com!i8ni785qtr.1!nntp.google.com!t9no1799855qtn.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.java.programmer Date: Fri, 5 Apr 2019 11:13:40 -0700 (PDT) In-Reply-To: <4ffe145e-d766-46ad-9c6e-e794450a195c@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=84.74.101.34; posting-account=UjEXBwoAAAAOk5fiB8WdHvZddFg9nJ9r NNTP-Posting-Host: 84.74.101.34 References: <636ed842-3212-4955-8c81-0a48f162b6b9@googlegroups.com> <4ce08746-597b-4aab-a53d-13aa3723b083@googlegroups.com> <4ffe145e-d766-46ad-9c6e-e794450a195c@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <2308a448-c264-421f-bea5-557c84ae9be0@googlegroups.com> Subject: Re: Does this make sense? From: bursejan@gmail.com Injection-Date: Fri, 05 Apr 2019 18:13:40 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Lines: 78 Xref: csiph.com comp.lang.java.programmer:38878 BTW: A close() would be also a needed option for=20 java.net.Socket access that is in progress, since=20 they don't react on interrupt(). Only some java.nio =20 can do it. But they just hook into the interrupt() and install a closer... Simple check out where this package private method of Thread is used: void blockedOn(Interruptible b) I don't know whether a WatchService also installs such=20 a closer while in progress. blockOn is accessed indirectly via SharedSecrets.getJavaLangAccess in the class AbstractInterruptibleChannel. But since the interface of WatcherService says, WatchKey take() throws=20 InterruptedException, I guess interrupt() is nevertheless supported by a WatcherService... On Friday, April 5, 2019 at 8:03:05 PM UTC+2, burs...@gmail.com wrote: > Actually I don't know exactly what IDEs do, > like for example IntelliJ. They could also follow > other strategies, like react on active/deactive >=20 > of window, or react on terminate of a ant job > or build job, etc.. Sometimes, if there are > too many changes, I already notices that >=20 > some of them might not be recognized. I also > don't know whether a watcher can report content=20 > change. Ok I see OVERFLOW, events may have been=20 >=20 > lost, and ENTRY_MODIFY(*), entry in the directory has=20 > been modified. Oki Doki, everything is there,=20 > but because of OVERLOW(*) I guess a tool needs=20 >=20 > a fallback strategy. >=20 > Thanks, interesting! >=20 > (*) > https://docs.oracle.com/javase/7/docs/api/java/nio/file/StandardWatchEven= tKinds.html >=20 > On Friday, April 5, 2019 at 7:57:13 PM UTC+2, burs...@gmail.com wrote: > > Instead of interrupt(), you might also=20 > > simply close the WatchService. It should cancel > > WatchKeys that are in progress. > >=20 > > https://docs.oracle.com/javase/7/docs/api/java/nio/file/WatchKey.html > >=20 > > Disclaimer: I have never used watchers. I > > guess some IDEs use it also, to get notified > > about changed stuff. So its quite useful... > >=20 > > On Friday, April 5, 2019 at 7:53:44 PM UTC+2, burs...@gmail.com wrote: > > > I think you don't need an extra thread. Since > > > Swing runs anyway in its own thread.=20 > > > If you display a non-modal window, the current > > > thread will not block. And you can perform > > >=20 > > > the for(;;) loop in the main thread itself, without > > > starting a thread. The problem is only, how does > > > the main thread get events from the watcher and > > > from the window? Well the same way, via interrupt(). > > >=20 > > > So the main thread can detect whether it go a > > > watcher.take() or whether it got interrupted. > > > And it can gracefully terminate and close also > > > whatever resources it has opened. If some tooling > > >=20 > > > shows an error somewhere, submit a bug report. > > > Lets see what they say... > > >=20 > > > On Friday, April 5, 2019 at 5:39:25 PM UTC+2, Eric Douglas wrote: > > > > On Thursday, April 4, 2019 at 8:33:50 PM UTC-4, Arne Vajh=C3=B8j wr= ote: