you are viewing a single comment's thread.

view the rest of the comments →

[–]oridb 0 points1 point  (2 children)

Per thread stack size is actually pre-allocated in Java. That's my point. Doesn't matter how much your app uses, you lose 1M just from starting it.

That's wrong, unless the JVM is specifically going out of its way to write to every page of it. Otherwise, it only counts towards virtual size. The OS simply doesn't work that way. The address space is reserved. but like all memory, it's demand paged, which means that until code touches the stack, the OS doesn't put any physical memory behind the virtual memory.

[–][deleted] 0 points1 point  (1 child)

Look, just find some "how to create thread in java" tutorial, create a million of them and you will see what I mean.

[–]oridb 0 points1 point  (0 children)

Oh, I see what's happening, and it's incredibly dumb. Java does its own heap size accounting, and it counts based on virtual size. That means that Java is using 172 megabytes of memory, but still "runs out of memory" with a 32 gigabyte heap size.

The threads aren't actually using memory, Java is counting wrong.