I've built a Java Socket server which listen to a post on my freebsd server.
The Server class listen to a port, and accept connection.
Every new connection is sent to the ServerManager which save it on a list, and iterate through it to check for new data. the iteration is done through an infinity while loop
.
I've noticed that after few days running the server has been killed. I don't know what killed it. Is it possible that the system killed it, like Android does to processes when low on memory and resources? Is there a way to avoid this? Maybe create some kind of a "Watch Dog" to relaunch it in case of it getting killed?
if the getInputStream().available() > 0 it runs a new thread for handling it
This is not correct. (a) It isn't necessary and (b) what happens if it is zero? Just spawn the thread for the accepted socket, have it deal with the input stream, using blocking reads, and close everything when it finishes (i.e. when read() returns -1 or an exception is thrown).
The accept loop shouldn't do anything with the accepted socket at all, except pass it to the new thread.