Stop the server's thread correctly