I created application in Swing and i want to run only one instance of it. I wrote something like this:
private static final int PORT = 12345;
{
try {
new ServerSocket(PORT, 10, InetAddress.getLocalHost());
} catch (UnknownHostException e) {
// shouldn't happen for localhost
} catch (IOException e) {
// port taken, so app is already running
System.out.println("Application already exist");
System.exit(0);
}
}
It works but only for all system. So if one user run it, another can't use it in the same time. So I want that each user could run only one instance of this application. Do you know how can i make it?