0

When I run my application using the .jar file, the GUI is displayed and javaw.exe shows up in System Processes in the task manager. But when I run the .jar file again without closing the first one, a second javaw.exe process starts and a second GUI is displayed. How do I stop this? I want there to be only one instance of my application at a time no matter how many times I run the .jar file.

3 Answers3

2

There are a couple of solutions here.

Note, though, that the socket solution needs to be modified if you are worried that something else on the same machine could be using the same port.

cybersam
  • 63,203
  • 6
  • 53
  • 76
1

One simple way is to open a socket on a fixed port number. The OS will enforce that only one process may do this.

Bohemian
  • 412,405
  • 93
  • 575
  • 722
-1

Register a value in a file, is probably the easiest solution.

Johan Frick
  • 1,084
  • 1
  • 10
  • 18