0

I have JavaFX application built and used as desktop app with an installer which created a shortcut on desktop. It works perfectly fine, but whenever clicks on shortcut, it opens a new window. I want to make changes to the app to act as singleton and open the same window if it is already opened.

Can anyone help?

Damu
  • 47
  • 9

1 Answers1

2

Each time you launch your application, you are creating another JVM. So what you want is a way to ensure that, at most, only one JVM of your application is running. So you need a way to find the running JVMs. One way is the JPS utility. Its output includes the name of the class that you launched. You can run JPS from java code using class ProcessBuilder. Alternatively you could write an operating-system script, i.e. PowerShell for Windows or bash for linux, to launch your application which would first run JPS to see if the application wasn't already running.

Abra
  • 19,142
  • 7
  • 29
  • 41