제 생각에는 SingleInstance
응용 프로그램을 찾고 있으며 일부 백그라운드 프로세스를 수행하기 위해 종료하지 않으시겠습니까?
제 3의 질문이지만, 첫 번째와 두 번째 질문에 대해 곧바로 대답 해 드리겠습니다.
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
checkIfRunning(); //Check first if the Application is aready running.
Parent root = FXMLLoader.load(getClass().getResource("fxml/main.fxml"));
primaryStage.setTitle("Hello World");
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.show();
Platform.setImplicitExit(false); //Prevent the Application from Terminating when it's close
}
public static void main(String[] args) {
launch(args);
}
/**The function for checking if the application is already running start here**/
private static final int PORT = 9999;
private static ServerSocket socket;
private static void checkIfRunning() {
try {
//Bind to localhost adapter with a zero connection queue
socket = new ServerSocket(PORT,0, InetAddress.getByAddress(new byte[] {127,0,0,1}));
}
catch (BindException e) {
System.err.println("Application already running.");
System.exit(1);
}
catch (IOException e) {
System.err.println("Unexpected error when checking if application is already running.");
e.printStackTrace();
System.exit(2);
}
}
}
시도해보십시오. 응용 프로그램을 닫으면 여전히 실행 중이므로 두 개 이상의 응용 프로그램을 시작할 수 없습니다.
제 3의 질문은 응용 프로그램의 매개 변수 (또는 데이터)를 전달하는 방법이었습니다. 아이디어가 소켓을 사용하기 때문에 데이터를 보내고 받기 위해 소켓을 사용합니다. – Happy
또는 소켓 또는 데이터 그램을 사용하여 응용 프로그램간에 통신 할 수 있습니다. – Polar