Java has about 100 parallel threads and memory management

I am writing an optimization algorithm to create about 100 threads At present, I start them once (for loop), and then I tell each thread that it should join ()

My problem now is that each thread uses a lot of memory, so heap space exceptions don't take a long time I want some arrangements, but I don't know how to achieve it

I have this idea: start 10 threads and start a new thread each time one of these is completed So run 10 threads until there are no threads

Does anyone have an idea or know how to achieve such a thing?

Thank you very much for your greetings from Cologne

Marco

Solution

Consider the number of cores in the machine you will use If the number of threads you run is equal to the number of cores, the performance will be the best As Kle said, use thread pools

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>