开发者

Thread management in Java

I need a solu开发者_如何学JAVAtion that allows to set a capped number of thread running on the system and that optimizes memory and CPU usage (for example, the size of memory will not grow over the known total thread stack memory), etc.

Is there a native Java technology for that or a third party library?

Thanks


Thread stack size is constant in Java, so you don't have to worry about individual thread size growing without bound.

If you're writing code that wants to do things in many threads and you want to make sure you don't consume more than a given number of threads, you can use something like a fixed thread count executor.

Do you want to limit the number of threads of a program that you have no other control over? You probably need to do something special for each operating system. Linux, for example, has no per-process thread limits (only a global limit common to all processes).


It looks like you search for something called "process accounting" but just for threads. Within one JVM this is not possible, every thread can consume all the memory of your JVM, and if it sets its priority to the highest value it will propably also "steal" CPU from the other threads in your JVM.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜