Re: how to prevent a jar executed only once in a machine



In article <1151688143.315164.248010@xxxxxxxxxxxxxxxxxxxxxxxxxxx>,
"John_Woo" <john_woo@xxxxxxxxxx> wrote:

Hi,

If my.jar is a swing UI app (or just a simple app), I'm wondering if
it's possible or how, that
this my.jar can be executed only once (no multi-session) in same
machine <or in same folder>?

Can any one tell?

--
Thanks
John
Toronto

There are a couple of common tricks used for preventing multiple
instances of an app from running.

One is to have your app open a ServerSocket on a specific port, which
prevents any other application on the same network interface from doing
the same (it'll already be in use when the second attempt occurs). But
this isn't always a good technique, depending on the port and other
factors.

Another is to create a file opened for output (I use a FileOutputStream)
and then obtain an exclusive lock on it. When the app terminates, the
lock is freed. I close the FileOutputStream at normal termination set
the file to delete when the JVM exits. When a second instance launches,
it may already find the file (in the event of an abnormal termination),
but it can't get a lock if another instance is running. I only use this
technique for restricting an individual user, so that the file is in the
user's home directory, but it can be readily adapted for system-wide use.

= Steve =
--
Steve W. Jackson
Montgomery, Alabama
.



Relevant Pages

  • Re: how to prevent a jar executed only once in a machine
    ... Steve W. Jackson wrote: ... If my.jar is a swing UI app, ... and then obtain an exclusive lock on it. ... If your app terminates abnormally -- or you forget to close the output ...
    (comp.lang.java.programmer)
  • Re: Lock problem - concurrent users
    ... Clipper 5.2 app at a client of mine. ... The app lives on a Win2003 Small Business server, ... Have you been able to determine if your lock routine fails to lock the ...
    (comp.lang.clipper)
  • Re: Execute on Focus
    ... then click the lock button. ... but it's VB6 code and I'd rather write my app in newer VB.net code. ... > Did you know that this is a VBNet newsgroup for some of us VB6 is more ...
    (microsoft.public.dotnet.languages.vb)
  • Re: vb application locks file
    ... But it seems you've narrowed it down to your own app. ... in releasing resources and you have evidently overlooked something. ... While possibly not associated with your current lock problem, ... The randomness or intermittent behavior also suggests that file i/o is ...
    (microsoft.public.vb.general.discussion)
  • How to read a partially locked file
    ... I'm having problems reading a partially locked file. ... The writer app (a 3rd ... My app tries to read the new data but since FileStream is ... The result is a lock exception when I try to read 1 byte that is within ...
    (microsoft.public.dotnet.framework)