When my Application, it bind on a given port when it started:
public boolean checkIsAlreadyStart() {
try {
final ServerSocket server = new ServerSocket();
server.setReuseAddress(false);
server.bind(new InetSocketAddress("127.0.0.1",APPLICATION_PORT ));
if (server.isBound()){
logger.debug("binding to port: {}", APPLICATION_PORT);
return false;
}
return true;
} catch (IOException e) {
logger.error("cannot bind to port", e);
return true;
}
}
However, when i run two instance of the Application at the same time, the second instance can still run the method without the IOException. Do I have to call accept() method?