Re: Limit Single Instance
- From: "Allan Bruce" <amb@xxxxxxx>
- Date: Tue, 31 Jan 2006 21:33:16 -0000
"Gordon Beaton" <not@xxxxxxxxx> wrote in message
news:43df96e5$1@xxxxxxxxxxxxxxxxxx
> On Tue, 31 Jan 2006 09:45:34 -0700, Monique Y. Mudama wrote:
>> On 2006-01-31, Allan Bruce penned:
>>> How can I limit my Java application to be running only once? I want
>>> to avoid a user being able to run the application twice, instead if
>>> they try to re-open it then it should show the main JFrame of the
>>> instance already running. Thanks Allan
>>>
>>
>> The typical way to do this (for any app, not just java) is to check
>> for a lock file on startup. If the lock file exists, don't start the
>> app. If it doesn't, create one.
>
> The other typical way is to open a ServerSocket listening on a
> specific port number. If that fails, you can assume your application
> is already running.
>
> This mechanism has two advantages:
>
> - the ServerSocket is automatically released regardless of how the
> application terminates, so no false positives are caused by failure
> to clean up (other applications or users using the same port number
> can still be a problem, so choose wisely).
>
> - a second program instance, upon failing to create the ServerSocket,
> can connect to the original and then exit, thereby signalling it to
> pop up or move to the front.
>
> /gordon
>
I had thought of something similar - my only worry is if a firewall does
anything to interfere with this?
Allan
.
- References:
- Limit Single Instance
- From: Allan Bruce
- Re: Limit Single Instance
- From: Monique Y. Mudama
- Re: Limit Single Instance
- From: Gordon Beaton
- Limit Single Instance
- Prev by Date: Re: Program will add but cannot get it to multiply
- Next by Date: Re: Program will add but cannot get it to multiply
- Previous by thread: Re: Limit Single Instance
- Next by thread: Stack And Heap
- Index(es):
Relevant Pages
|