only one instance

C

Chameleon

I want only one running instance of my app.

There are 2 methods:

1. sockets
2. locking files (I prefer this)



But my big problem is this:

When I run the 2nd instance of App with a file parameter:

my_app.jar a_file.txt

I want to pass "a_file.txt" to 1st instance for opening and then 2nd
instance terminate.

How can I do this?


sorry for my english
and thanks
 
T

Thomas Hawtin

Chameleon said:
I want only one running instance of my app.

1. sockets
2. locking files (I prefer this)

When I run the 2nd instance of App with a file parameter:

my_app.jar a_file.txt

I want to pass "a_file.txt" to 1st instance for opening and then 2nd
instance terminate.

The obvious solution is to use the socket method of running a single
instance of the app. The second app then connects to the socket and
transfers the filename.

Tom Hawtin
 
S

steve

The obvious solution is to use the socket method of running a single
instance of the app. The second app then connects to the socket and
transfers the filename.

Tom Hawtin


I sometimes get problems with the socket approach, if the main app shuts down
for some reason (and does not kill the signaller),the socket app ( running in
another thread) holds the jvm open ,and requires a 3 finger salute.
otherwise it prevents the user from re-starting a new app.

the another way is to get the program to write a java "temp" file to a
directory with no other file in.

then when you start the app, count the files in that directory.
( i have not yet seen java NOT clean up it's temp files)

Do not create a "Normal user file", but a Java TEMP file.

Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top