0

Is it possible to define the max heap allocation for a specific new thread (considering a limit below the max heap size allotted to the JVM)?

Example: setting the VM to -Xms=24m -Xmx=48m and programmatically set a max thread heap size of 8m

Jim Jones
  • 18,404
  • 3
  • 35
  • 44
Matteo Baldi
  • 5,613
  • 10
  • 39
  • 51
  • As far as I am aware the Heap is shared memory for all Threads, the only thing they have is their own virtual stack which can be set to a minimum but not a maximum size with the `-Xss` flag. – Ben May 04 '18 at 10:42
  • https://stackoverflow.com/a/8893973/612920 – Mansuro May 04 '18 at 10:42

1 Answers1

2

No you can't, simply because heap is shared across threads by design. However if you have a stackoverflow (thread specific), there is -Xss to change the stack size. Unless you are fighting stackoverflow, you are unlikely to need to change that.

(However, if you are really needing this, you might try to do managed off-heap allocations, thus giving you back so control of how memory is used, but dealing with bytebuffers is terribly inconvenient compared to objects...)

user2023577
  • 1,752
  • 1
  • 12
  • 23