java


Modify JVM args from inside the JVM


Is there a way to modify the jvm args from inside of the jvm? Specifically, I want to be able to change the maximum heap size of the jvm from inside of it. Is this possible?
Edit: I guess I should add the reason I wanted to do this. I have a few Java programs that are run on different machines/platforms. These programs have configurations that are sourced at runtime and are different depending on the machine/environment the program's running one. Some of these configurations can be changed at runtime and the various programs automatically update themselves as the configurations change.
I wanted heap size to be one of these configuration parameters that is sourced at runtime like the rest of the configuration. If so, then the program could startup (with some default jvm args) then adjust itself based on the retrieved config.
This is a halfway-serious, completely-off-the-wall hack-thought:
...what if you spawned a new instance of java (with the new settings) from the current jvm then killed the old process from the new? I have no idea if this will help or not (or even work)...
You cant change those options simply because it compromises the security of the system.
If an admin wishes to only allow a certain program to have certain capaibilities by setting a security manager, it would be a serious problem if you could turn that off.
Anyway a program should not be changing stuff like its memory requirements at runtime - these should be known and setup by the administrator. There is no reason why your program should need to do this at runtime. If it really needs to change this perhaps the reason qustion is why doesnt the admin type dude not do it ?
Specifically, I want to be able to
change the maximum heap size of the
jvm from inside of it. Is this
possible?
No.
With JRockit you can at least suggest a heap size.
JVMFactory.getJVM().getMemorySystem().suggestHeapSize(100*1000*1000);
See JMAPI for more information
(Years later), I found a library that accomplishes what I needed at the time I posted. Akuma is a library for daemonizing Java processes. It allows restarting the JVM with new arguments.
The difference between using this and launching a new process with a bootstrap is that stdin/stdout and other file descriptors are automatically shared.
As noted by others, this is generally only possible by having a bootstrap program (Java or other language) that invokes the main JVM with the right parameters.
That said, are you sure this is necessary? You mention "maximum heap size". If you are referring to the -Xmx parameter: This is just a limit the VM may never exceed. It does not mean the VM will really use that much, it will do with less if it can.
So you can always set -Xmx to the maximum the system can handle, and let the JVM decide how much it really needs. Why do you think you need to set it dynamically?
Dynamically setting -Xmx for instance would be very helpful for controlling projected system resources (primarily footprint) for long running runtimes. One of many ramifications of course is bigger/longer GC overhead.
I know several large server machines running dozens and dozens of 1G+ heap JVMs. If these runtimes could have their high water mark scaled back during low-use times then you could hard manage your system resources much better.

Related Links

What is the new method to make a client server request from previously used depricated class DefaultHttpclient,HttpGet ,HttpResponse?
First Non Repeating Character using hashmap in one loop?
Shift/reduce conflict in java cup - dangling else issue
Programme running on Netbeans but not on CMD
How to analyze time complexity here?
Android error using json Caused by: java.lang.NullPointerException [duplicate]
Java Socket - Bind Object to IP
Write top k values of RDD to a file in Spark
How to convert db BLOB column to a byte[] with EntityManager without defining #Entity?
Running a class on button press?
How do I enable Android Studio/IDEA closure folding for anomynous class in Java 8?
Apache httpcomponent returns java.net.UnknownHostException: Name or service not known
Create an instance of an abstract class in Kotlin
Sonar maven analysis - class not found
Tic Tac Toe block winning move
ANDROID - Fragment - Downloading file from Parse backend, saving it in External Storage, then creating Application Chooser

Categories

HOME
pandas
log4j
openmp
office365api
electron
spagobi
amortized-analysis
c#-2.0
disassembler
azure-media-services
amazon-cloudformation
numeral.js
collectd
dynamics-crm-online
iolanguage
serverless-framework
clojurescript
django-admin
jprofiler
graphicsmagick
wijmo
shopware
one-to-many
cas
dynamic-featured-image
strncpy
objectanimator
nat
twilio-api
semantic-versioning
calibre
catch-all
framemaker
form-data
language-concepts
amazon-kinesis-kpl
html5-fullscreen
suricata
hot-module-replacement
android-browser
abstract-class
sqlite2
streamreader
greenrobot-eventbus
mesos-chronos
ruby-on-rails-3.1
node-gyp
botbuilder
mime
bootstrap-dialog
sencha-touch-2.3
flickr-api
revapi
powercli
gabor-filter
yii2-extension
forever
slickedit
worker-thread
magma
dtexec
pillow
cudafy.net
specrun
pycaffe
time-and-attendance
firmata
savon
database-optimization
google-web-starter-kit
jwplayer7
whois
pickadate
rhino-servicebus
system.management
historian
wireshark-dissector
service-accounts
p2
javax.mail
ng-animate
qcodo
rdtsc
starcluster
srs
flexmojos
mysqltuner
ccss
jsctypes
listings
odata4j
ril
limejs
flashvars
selected
labwindows
errai
getmessage
tomcat-valve
yui-datatable
oncheckedchanged
mongomapper
datareader
wise
procedural-music
private-members
data-acquisition

Resources

Encrypt Message