code optimization for worker thread management