Code the closure of an application

Asked

Viewed 60 times

2

Hello, good afternoon everyone!

I have a problem with the company’s software. I created a serverSocket when starting the application, and with this I can control so that only one application is opened on the same machine. However, when closing the system, I need to give a . close in the serverSocket created, so that the access to the system is free.

I can in no way create a method that is called in the act of closing the system. In addition to controlling the socket, there are numerous needs that could be implemented in closing the application. So I really need your cooperation. Thank you.

1 answer

0


In its main class, namely the one that extends from Application and has the method start(Stage stage) implemented, override the method stop() and implement what you wish in it:

@Override
public void stop(){
    // TODO
}
  • Math, hey, hey, hey! I did the way you said, only I can’t debug, the application is desktop, and when I close (through the same red X) does not pass the stop() method. Anyway, for initial need was to close the socket created, researching found that when closing the application the socket is automatically closed and dispenses with this implementation. Thank you for the reply!

  • But can you debug the rest of the code? I circled here and worked ok, including debug

  • Did you even build a clean before debugging? Just to confirm, because I can’t imagine what else it might be

  • Yes, I did, I removed the comment pq sent wrong to you, look: private Static Serversocket s; @Override public stop() { if (s != null) { Try { s.close(); } catch (Exception ioe) { e.printStackTrace(System.err); } } Platform.Exit(); System.Exit(0); }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.