Why do you need to specify the Java heap size?

Viewed 1736

I have always wondered, why does Java require you set the heap size manually? I was under the impression that programs written in other languages would just allocate as much memory as needed as the program run until the OS could allocate no more.

In the Java world we need to set the heap, stack, and permgen size. While this is simple enough forgetting to increase these to "large enough" numbers is the #1 reason I have seen servers go down.

Why is it not possible to tell Java to grow the heap/stack/permgen as much as it needs over time?

5 Answers

Old topic but I got here and I think I know the answer.

Complementing what Peter said, the Java ecosystem is entirely designed for system administrators and support teams. In the same way that the administrator defines the memory resources that he wants to be used by the application, the same happens with database connections (JNDI) in which you do not need to give the application or your developer where the database production is, just the name that references the resource. Everything Sun did had a perfect mission-critical management system. In the case of the Solaris operating system, Sun has developed a feature called "projects" (https://docs.oracle.com/cd/E37838_01/html/E61042/index.html) that serves for the administrator to limit server resources in applications of any programming language (as you mentioned above). Therefore, it is important for a production system to let the system administrator know how much resources the application is able to use and to be able to limit what is necessary. And this is not unique to Java or Sun products. In the case of .NET it is possible to limit these resources (https://docs.microsoft.com/en-us/iis/configuration/system.applicationhost/applicationpools/add/processmodel), Ruby (https://gist.github. com/jjb/7389552), Node.JS (How do I determine the correct "max-old-space-size" for node.js?) and etc.

Learning to manage is important like learning to develop. A lot of people think Docker is a modern marvel while FreeBSD Jails, Solaris Zones and so on existed a long time ago. What makes good software not fail is that it is well written and well managed.

Related