0

All I want is to show the GUI on the already started app. I have file.lock in place singleinstance style app. I want something lightweight not IPC or javaspace.

Was thinking to have a Server.accept() to ping the already started app and make it do setVisible(true) But that would probable lead to trouble if port is in use. One could set up a port number table/algorithm to follow if first port is taken but then again its a bad idea.

What you think, what are the alternatives?

ThinkingStiff
  • 64,767
  • 30
  • 146
  • 239
Erik
  • 5,039
  • 10
  • 63
  • 119
  • are you meaning `SingleInstance` http://stackoverflow.com/questions/8223527/check-for-single-instance-java-program – mKorbel Nov 22 '11 at 20:15
  • i already have the SingleInstance setup but my app have a Tray icon and sometimes app GUI is hidden. If user start another instance of the app, that instance must bring the first on to setVisble(true) and the commit exit(0) – Erik Nov 22 '11 at 20:20
  • then http://stackoverflow.com/questions/6134694/restrict-multiple-instances-of-an-application-in-java – mKorbel Nov 22 '11 at 20:23
  • thanks for the link but as i stated above i already have singleinstance setup. – Erik Nov 22 '11 at 20:30

1 Answers1

1

Listening on a port is probably the best way--at least the most reliable one. Another option is writing out a file and looking for it but that leads to problems when your computer crashes and the file isn't deleted.

If you can't bind to the port, that alone might be an indication that a server is running.

If you wanted the ability to recover, send a message and expect a specific response back on the port. If you can't bind to the port and don't get a response from the port then it might not be you, so prompt the user with an "Is this app already running" dialog.

Bill K
  • 62,186
  • 18
  • 105
  • 157
  • yes "Is this app already running" dialog. could be a solution if I had the GUI in the app list bar, but the only visible part is a Tray icon. So i must find a way to make setVisible(true) – Erik Nov 22 '11 at 20:26
  • 1
    of course one could send up a msgbox that app is running and ask the user to click the Tray Icon. Yes that is an accepted and recognized behavior. Problem is solved i think thanks for the headsup – Erik Nov 22 '11 at 20:32