Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!us.feeder.erje.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: Knute Johnson Newsgroups: comp.lang.java.programmer Subject: Re: single instance Date: Wed, 16 Jan 2013 17:14:14 -0800 Organization: A noiseless patient Spider Lines: 34 Message-ID: References: <50e8eb1f$0$284$14726298@news.sunsite.dk> <50f6f198$0$285$14726298@news.sunsite.dk> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Thu, 17 Jan 2013 01:14:16 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="aba33539224e5c782fe0c4053f7756fd"; logging-data="3655"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Fn1NurRM2Ng1XneeObFdg" User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130107 Thunderbird/17.0.2 In-Reply-To: <50f6f198$0$285$14726298@news.sunsite.dk> Cancel-Lock: sha1:LSxt7A/Cluxfgv8urKcVNE1eGoA= Xref: csiph.com comp.lang.java.programmer:21459 On 1/16/2013 10:29 AM, Arne Vajhøj wrote: > On 1/16/2013 1:51 AM, Roedy Green wrote: >> On Sat, 05 Jan 2013 19:49:08 -0800, Knute Johnson >> wrote, quoted or indirectly quoted someone >> who said : >>> The risk is, that in Windows anyway, where the system clock granularity >>> is 17ms it is possible to start two copies of a program with a batch >> >> I have been studying Knute's code and Peter's commentary hoping to >> come up with a canned package for ensuring single Instance. >> >> Using system.nanotime aught to help avoid granularity trouble. > > 1) It uses a smaller unit, but does not guarantee a smaller > granularity. At least on my version of Windows, it was much finer. > 2) It is only guaranteed to work within the same program as > the base is not fixed. > > 3) No matter how small a granularity, then it still just reduces > the risk of concurrency problems but does not eliminate the risk. > > Arne It doesn't have to be perfect just good enough to stop what you want to stop. For the application I have, I'm not worried about somebody starting two copies with a batch file only by clicking on an icon or typing into a command line. For that it will be more than adequate. -- Knute Johnson