support specity Thread number

1. Support to specify the Thread number.
2. Code refactor.