By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,542 Members | 1,097 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,542 IT Pros & Developers. It's quick & easy.

Optional single application instance enforcement and multiple startup notification

P: 7
kindly give java code

how to run a single instance in java for exe application based on gui
Jan 24 '07 #1
Share this Question
Share on Google+
19 Replies


10K+
P: 13,264
kindly give java code

how to run a single instance in java for exe application based on gui
Can you be more specific? Do you want to know how to run a Java program?
Jan 24 '07 #2

P: 7
hello,


iam working in java GUI Based program with Swings

for eg: if i started yahoo messanger only single instance is going to be created

if at all ur try ing to open new it will open existing window on the tool bar
similarly i want to make my java exe to be single instance.

so possibly send any java code if u have or send nice idea to do
Jan 24 '07 #3

10K+
P: 13,264
hello,


iam working in java GUI Based program with Swings

for eg: if i started yahoo messanger only single instance is going to be created

if at all ur try ing to open new it will open existing window on the tool bar
similarly i want to make my java exe to be single instance.

so possibly send any java code if u have or send nice idea to do
How many frames do you have in your program? Are you saying you want only one frame to be opened at a time? Please post the codes you have and explain exactly how you want the program to behave, I still don't understand what you are talking about.
Jan 24 '07 #4

P: 7
How many frames do you have in your program? Are you saying you want only one frame to be opened at a time? Please post the codes you have and explain exactly how you want the program to behave, I still don't understand what you are talking about.
hello excuse me,
i have only one frame, where my main method is going to be executed, in my program.and now i want it to be executed only once,if at all i want to open it again,it must be redirected to the same instance saying that the program is already running.
example:yahoo messenger.
hope u got it.give proper code related to it,its urgent.
Jan 24 '07 #5

10K+
P: 13,264
hello excuse me,
i have only one frame, where my main method is going to be executed, in my program.and now i want it to be executed only once,if at all i want to open it again,it must be redirected to the same instance saying that the program is already running.
example:yahoo messenger.
hope u got it.give proper code related to it,its urgent.
How is this program going to be run?
Jan 24 '07 #6

P: 7
How is this program going to be run?
Hi,

I developed a swing based application in java. I am running it through the executable jar. Each time clicking on the jar file it opens the new instance of the appliction.

But I want to open the single instance of the application i.e. If the application is running , then user tries to open another instance it should be display the error or running application only like yahoomessenger,notepad,etc.

Please tell me how it is done in java. send aly sample code or resources regarding this.

We r using netbeens ide to run the programs and how do u
Jan 24 '07 #7

10K+
P: 13,264
Hi,

I developed a swing based application in java. I am running it through the executable jar. Each time clicking on the jar file it opens the new instance of the appliction.

But I want to open the single instance of the application i.e. If the application is running , then user tries to open another instance it should be display the error or running application only like yahoomessenger,notepad,etc.

Please tell me how it is done in java. send aly sample code or resources regarding this.

We r using netbeens ide to run the programs and how do u
If only you had explained like this first time.
I'm not sure about this but if you make the program a thread and give it a name and then check against that thread before running the program
Jan 24 '07 #8

P: 7
If only you had explained like this first time.
I'm not sure about this but if you make the program a thread and give it a name and then check against that thread before running the program
Hai,
U said to check the thread.But can u tell me how to find a thread which is in running state and probably OS which is handling.If we can get that then probabaly we can know before next instance has been created .Don't guess the answer just let me know if u really have answer to it.
Jan 24 '07 #9

10K+
P: 13,264
Hai,
U said to check the thread.But can u tell me how to find a thread which is in running state and probably OS which is handling.If we can get that then probabaly we can know before next instance has been created .Don't guess the answer just let me know if u really have answer to it.
No problem. You can check for yourself here if you think I might make a mistake. Why do you want to know the OS as well?
Jan 24 '07 #10

P: 7
No problem. You can check for yourself here if you think I might make a mistake. Why do you want to know the OS as well?
you have given link to thread class but it is of no use for me.

MY question is suppose One.java is file which have a thread in it By name "DemoThread' (name of thread) .when i compile and run One.java my DemoThread is going to run aswell. Now if i try to create again new instance of same class ie One.java at that particular time how can my One.java file know that already DemoThread is running as i did not stopped my first instance.

prob this might have made u little bit clear.
Jan 24 '07 #11

10K+
P: 13,264
you have given link to thread class but it is of no use for me.

MY question is suppose One.java is file which have a thread in it By name "DemoThread' (name of thread) .when i compile and run One.java my DemoThread is going to run aswell. Now if i try to create again new instance of same class ie One.java at that particular time how can my One.java file know that already DemoThread is running as i did not stopped my first instance.

prob this might have made u little bit clear.
Perhaps you've never used threads before then.
Here is another method which should be easy for you to grasp.
Use the System class.
When the instance is created check to see if a property is set using the getProperty method. If not, set a property, give it a key and continue with the instantiation otherwise the program is already running so exit.
Jan 24 '07 #12

P: 18
kindly give java code

how to run a single instance in java for exe application based on gui
Why do you want to run only one instance?
-- Abdel Olakara
Jan 25 '07 #13

10K+
P: 13,264
Why do you want to run only one instance?
-- Abdel Olakara
http://olakara.googlepages.com
Hi Abdel.

The OP made another post for the same problem. I'll merge the posts.
Jan 25 '07 #14

P: 1
Did you got the code for this problem.If yes can you please send me that code to me.It's urgent.
Thank you...

kindly give java code

how to run a single instance in java for exe application based on gui
Nov 20 '07 #15

Expert 10K+
P: 11,448
If only you had explained like this first time.
I'm not sure about this but if you make the program a thread and give it a name and then check against that thread before running the program
That won't work: when you click on a jar another java(w) process is started. Two
different processes can't see each other's threads.

Better just create a simple lock file or have the appliation try to open a socket,
if the file already exists or if the socket is already open another instance is
already running.

kind regards,

Jos
Nov 20 '07 #16

10K+
P: 13,264
That won't work: when you click on a jar another java(w) process is started. Two
different processes can't see each other's threads.

Better just create a simple lock file or have the appliation try to open a socket,
if the file already exists or if the socket is already open another instance is
already running.

kind regards,

Jos
About this javaw process, is there a way of distinguishing between two javaw processes started by two different jar files?
Nov 20 '07 #17

Expert 10K+
P: 11,448
About this javaw process, is there a way of distinguishing between two javaw processes started by two different jar files?
Dunno; using Unix or Linux I can see it in my ps or top list (ordered by age so I
can see which one was started first) but I have no idea how to do that on Windows.

kind regards,

Jos
Nov 20 '07 #18

10K+
P: 13,264
Dunno; using Unix or Linux I can see it in my ps or top list (ordered by age so I
can see which one was started first) but I have no idea how to do that on Windows.

kind regards,

Jos
Probably some meddling with task manager ...
The socket approach is the best way here. Or even have the program write/create a file. When another instance starts just check for/in that file.
Nov 20 '07 #19

Expert 10K+
P: 11,448
Probably some meddling with task manager ...
The socket approach is the best way here. Or even have the program write/create a file. When another instance starts just check for/in that file.
Yup, as I wrote above; I normally use the socket approach but a simple file
(with the pid written in it) does fine too. I don't know how to check if another
pid is still alive on Windows though.

kind regards,

Jos
Nov 20 '07 #20

Post your reply

Sign in to post your reply or Sign up for a free account.