I am using jetty server to receive calls from http clients.
I am using BufferedWriter object to write a log file for debugging.
The server is always running in order to receive calls.
How can i tell the program to only close the stream (log_file.close) when the server stops?
I am not supposed to stop the server, but before the program terminates (when i touch the terminate button for example) how can i close the stream file in that point?
If your code is running inside a web application (aka war) you can (and it’s actually a best practice) to implement
ServletContextListenerand register it in yourweb.xml.In
contextInitializedyou can make the necessary init operations.In
contextDestroyedyou can close the stream.