Re: how to prevent a jar executed only once in a machine
- From: "Steve W. Jackson" <stevewjackson@xxxxxxxxxxx>
- Date: Fri, 30 Jun 2006 12:40:25 -0500
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
.
- Follow-Ups:
- Re: how to prevent a jar executed only once in a machine
- From: John_Woo
- Re: how to prevent a jar executed only once in a machine
- References:
- how to prevent a jar executed only once in a machine
- From: John_Woo
- how to prevent a jar executed only once in a machine
- Prev by Date: how to prevent a jar executed only once in a machine
- Next by Date: Re: Efficient writable character buffers in Java
- Previous by thread: how to prevent a jar executed only once in a machine
- Next by thread: Re: how to prevent a jar executed only once in a machine
- Index(es):
Relevant Pages
|