Re: Limit Single Instance




"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


.



Relevant Pages

  • Re: Limit Single Instance
    ... >> How can I limit my Java application to be running only once? ... If the lock file exists, ... specific port number. ... - the ServerSocket is automatically released regardless of how the ...
    (comp.lang.java.help)
  • Problem with JNI and Tomcat
    ... This DLL is used to communicate over a RS232 port, and it must notice any event that occurs on the port to the java application. ... the nativeOpenPort functions looks for the "notifyEvent" Java method in the object that called it, in order to notify events when they occurs, and saves it in the "eventNotifyMethod" of the SERIALPORT structure ... private int portType; ...
    (comp.lang.java.programmer)
  • Re: RS232 data to Access database - general approach
    ... java involved and your lovely project can have many elegant solutions. ... the moment the user connects the handheld to the serial port. ... > measurement is made. ...
    (comp.lang.java)
  • Re: RS232 data to Access database - general approach
    ... java involved and your lovely project can have many elegant solutions. ... the moment the user connects the handheld to the serial port. ... > measurement is made. ...
    (microsoft.public.access.externaldata)
  • Re: what kind of non microconroller app are done in forth?
    ... utils and apps for it etc.. ... The Java guys tried to widen that bottleneck. ... It ought to be easier to port one particular Forth compiler than a java ...
    (comp.lang.forth)