updated code to work with num_threads >1 at td-agent restart