How to cleanly close the specified thread