Issue
@Override //// When the main runs
public void start(Stage stage) throws Exception {
this.primaryStage = stage;
primaryStage.setTitle("UzPos");
File f = new File("C:\\Windows\\checkFile");
if (!f.exists()) {
f.createNewFile();
} else {
new Alert(Alert.AlertType.ERROR, "App Already running", ButtonType.OK).showAndWait();
return;
}
f.deleteOnExit()
}
This code works cool, but here is one problem. When I force stop the app from Intellij IDEA by stop button, I detected that checkfile is not deleted automatically. Is there any way to get that kind of fuction? I want to work only one instance of my app. Thank you in advance.
Solution
I solved single instance applications using sockets instead of files. The code is Open Source. Feel free to have a look at it.
Or consider to use Drombler FX, the modular application framework for JavaFX, which provides this (optional) feature out of the box. There's also a Getting Started tutorial.
Answered By - Puce