I currently have a program that creates a bunch of tasks and then wait for them to complete. This is fine and all but it means that sometimes, it will create 50 tasks at once. This causes locking issues on my database. So in order to reduce these errors I would like to limit the number of threads to say, 16.
I've googled a bit and coming from Java, I don't see a way to create something like a "Threadpool" and limiting its size to 16 and then waiting for all the tasks to complete. How can I do this?