Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!weretis.net!feeder1.news.weretis.net!news.szaf.org!feedme.news.telefonica.de!telefonica.de!newsfeeder.ewetel.de!border3.nntp.ams.giganews.com!Xl.tags.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!local2.nntp.ams.giganews.com!nntp.bt.com!news.bt.com.POSTED!not-for-mail NNTP-Posting-Date: Sun, 06 Jan 2013 07:36:04 -0600 From: "Chris Uppal" Newsgroups: comp.lang.java.programmer References: <50e8eb1f$0$284$14726298@news.sunsite.dk> Subject: Re: single instance Date: Sun, 6 Jan 2013 13:34:23 -0000 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5512 X-RFC2646: Format=Flowed; Response X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5512 Message-ID: Lines: 24 X-Usenet-Provider: http://www.giganews.com X-AuthenticatedUsername: NoAuthUser X-Trace: sv3-RwuB+l1+JWUn3wzyZ6rCxHr3zqP9/D6lYcrim5WkZu7qrUpAt8dGRnBZmnI8DFkoizRJn1+c6ZF3/qC!7RgD9pTLQmA5WmqLhfwDJKaXR5z85BjSr3WWYxYwRouhaNNE67OZR+7ArMlcSHQLlEXT/ORNwsQ= X-Complaints-To: abuse@btinternet.com X-DMCA-Complaints-To: abuse@btinternet.com X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2261 Xref: csiph.com comp.lang.java.programmer:21023 Arne Vajhøj wrote: > Who can see a concurrency problem in that logic? There is clearly no way to avoid concurrency problems without either the cooperation of the OS, or the cooperation of some always-running service. Since Java has no way to create always-running services (i.e. any such solution is necessarily OS-dependent), it seems better to let the OS handle it for you. The only OS services (that I know of) that can be used for this, and which are also available despite Java's least-common-denominator philosophy, are network related. To me the approach of opening a server socket at a fixed (but configurable) port number seems by far the simplest approach. Also things built over that, such as setting up a small RMI server, might make sense (e.g. to simplify the logic of passing over the invocation arguments to the previously running process). If you can live with (partial) OS-dependence then you might also try using java.nio.channels.FileChannel.lock() or tryLock(). -- chris