Reputation: 12452
Related question: What are the Xms and Xmx parameters when starting JVMs?
Why do Java programs lets you specify -xms and -xmx? As a developer, why do I need to know/be concerned for how much cpu/mem my program will use upfront?
Or same question in different angle, why would not let Python specify these types of options? (worked in Python for 5 years and never had to do this)
Does it have to do with Python being interpreted language and Java being some sort of bytecode to JVM to machine language thing?
Or maybe something to do with how garbage collection is being done differently that Java needs to be more wary of memory consumption?
Upvotes: 2
Views: 9752
Reputation: 3240
Just a thought!
Upvotes: 0
Reputation: 20224
I think this is a question about the design pattern of java. It is really strange as that java is mostly the only one which strictly limits its memory usage. And it is also mostly the only one which has checked exception.
I believe these things are all because that the designers of java wants to design a language which is really for enterprises. They are trying their best to make it safe.
Here is an answer about the limitation of memory usage: https://stackoverflow.com/a/3358383/5588279
And for checked exception, that's the same. Designers want to force developers to handle every expectable exceptions.
Well, it's hard to say if that's good. Although I don't like this design as it seems that the designers treat me like a noob, but I have to admit it really makes java somehow safer... Maybe?
Upvotes: 2
Reputation: 2969
Not all operating systems communicate memory "pressure" to your running process in the same way, meaning nearly-never. Java lets you put an explicit limit on its memory use. Python, Go, and others have a somewhat aggressive method of collecting memory.
This is complicated by cgroups, used to implement containers under Docker and Kubernetes, which may note cause malloc()
to return NULL, but to cause a signal be sent to your process to kill it.
FWIW, the JVM gives you a means (by -Xmx
) to control the virtual machine's memory usage where as other systems just hope they fit. Java in a Docker container is very manageable where as Python or Go is a bit more hit-or-miss. These are all "good" technologies, but limits on containers should (I would hope) push for improvements in in how garbage collection "effort" is expressed. :\
This feels like a non-answer, and for that I'm dissatisfied. You can read this until someone posts something folks like better and up-vote. I'll delete this once a few inevitable grump-votes show up. ;)
Upvotes: 5