Is there a way to put maximum memory usage limit on each thread in Java?

后端 未结 4 892
遇见更好的自我
遇见更好的自我 2021-01-18 13:38

When we start threads in a Java program, is there any way for us to assign memory limit to each one of them?

I mean we assign something like this for a

4条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-18 14:35

    To place a limit on each thread you need to run each thread in a seperate process.

    Threads share memory so there is no way to assign memory to a specific thread automatically. However you can do the calculations yourself in code (for each data type of interest) and manage how much memory each thread is using.

提交回复
热议问题