add the numOfThreads to control the number of threads