Implemented graceful termination of all or selected server threads and the main thread.