EDIT I don't want to use Java Web Start
I've got a Java application that I'd like to run with different VM parameters depending on the amount of memory the system it is launched on has.
For example if the machine has 1 GB of memory or less I'd like to pass "-Xmx200m" and "-Xmx400m" if it has 2 GB and "-Xmx800m" if it has 8 GB (these are just examples).
Is there a portable way to do this?
I've tried having a first tiny Java app (hence portable) that determines the amount of memory available and then launches a new Java app but I don't think this is very clean.
As of now I've written Bash shell scripts that invoke the Java app with the correct parameters depending on the config but it only works on Linux on OS X.
What is the correct way to solve this?
Would application packager package ;) help ?
Are you sure you want to do this? In general, Java application need a certain amount of memory, not more, not less.
If you have a machine with little memory and you specify a small number at -Xmx you risk to run out of memory.
If you have a machine with lots of memory and you specify a large number the application won't use all the memory but only the amount required by the objects in use.
So, in general, you don't lose memory by specifying large numbers at -Xmx.
(Exceptions are server applications which have a large amount of object 'throughput' and tend to waste memory.)
What's your gripe with your current approach, exactly? It's completely portable (unlike various scripting solutions... why is a script "cleaner" than 100%-portable bytecode?), and it'll adapt perfectly if the hardware changes after installation (so it's better than capturing the hardware details as part of your installation script).
If you can explain the actual issues it may be easier to come up with a solution to those specific problems.
Here's an alternative that you might like better, actually: copy what Photoshop, GIMP, etc. do and make "resource usage" or "performance" part of the preferences for your app. You'll have to prompt them restart your app when/if they change this setting (to relaunch your app using the modified start procedure, since you can't change the memory limits for a running app... where you write the new flags is deployment-method dependent), but that's not such a disaster for a setting they'll likely change exactly once.
You could also check their hardware on first run, and if your default installed setting is way off from their setup, prompt them to change the setting then.
Since http://ant.apache.org :
I suggest that you
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With