optimize thread id getting