Smarter way to define maximum amount of threads