Creating thread dynamically in a thread pool

p4ddy prdpsbhat at
Tue Nov 30 07:56:13 UTC 2010

Hi all,

Here is the story.

I m handling threads for some server. maxThreadPoolSize is given as 1000 but
obviously creating 1000 threads not only takes time but also huge resources.
So am thinking of creating threads dynamically for the thread pool.
Initially say 100 threads will be created and based on certain factors, more
number of threads will be created and added to the pool.

As I m new to thread pooling, i have certain doubts:

1. how to determine initial number of threads? currently i have set it to

2. how to determine when to create next batch of threads? currently i m
creating another batch of threads as soon as the number of active threads
reaches 70% of the total threads.

3. what should be the batch size? currently i have set it to 100. so with
every batch, 100 threads will be added to the pool

4. another doubt is regarding memory allocation. currently i m allocating
memory to all the 1000 threads initially but threads are getting created
only when there is a requirement. Is this good? or should i allocate memory
dynamically too?

Hope to get some answers/opinions :)

Thanks in advance.
View this message in context:
Sent from the freebsd-threads mailing list archive at

More information about the freebsd-threads mailing list