Shutdown method to close all threads