How does one measure how many threads to create within a given jvm, to provide optimal performance? I ask because Im writing an application that must make a threaded request of SAP for every order number it finds in an database. It seems unreasonable that I allow this to be an open-ended number of threads, even though my employers will never have an infinite amount of orders in their database. I'm thinking of writing some kind of optimization algorithm using Runtime.freeMemory(), totalMemory() and maxMemory(). Is there a better alternative?