Optimize the thread close