Tell me how to catch the event in the netbeans console program stop, tried addShutdownHook, but it does not work when you click on the program stop button.

  • Is your console application? Do you have access to the sources? - LukavskyM
  • Yes, there is nothing special to show, there is a server and a client. The server is in an infinite loop in which it waits for clients to connect. The client and the server exchange data with each other when the server is stopped via netbeans. The objects containing the client information should be serialized to a file. - medvenot

1 answer 1

Stopping the program via netbeans most likely via the KILL -9 system signal. This signal cannot be processed by java , because jvm when it is received immediately completes its work.

For signal processing, besides the hook mechanism, you can use the sun.misc.Signal class, but it will not help in this situation either.

  • And then what will help? - medvenot
  • Nothing will help. In general, it is not correct to stop the program in this way, only hung-up applications use the kill -9 signal. - Artem Konovalov