1

considering the following command

java -Xmx1024M -jar app.jar arg0 arg1

The question is, how could I get the java input arguments here? I mean how could I get the -Xmx1024M?

Thanks in advance

  • Answered question http://stackoverflow.com/questions/1490869/how-to-get-vm-arguments-from-inside-of-java-application – Yuriy Chulovskyy Jan 24 '14 at 12:48
  • Do you need to get these arguments from code or command line? – Jakub Kubrynski Jan 24 '14 at 12:50
  • @JakubK yes dude, I want to halt the application if `-Xmx` argument hasn't set, another question, is it possible to increase the heap memory size during runtime? –  Jan 24 '14 at 12:55

2 Answers2

2

You can list arguments by using RuntimeMXBean:

List<String> arguments = ManagementFactory.getRuntimeMXBean().getInputArguments();

Unfortunately it's not possible to change java heap size limits at runtime

Jakub Kubrynski
  • 13,724
  • 6
  • 60
  • 85
1

If all you want to do is ensure that your application has sufficient memory, you can use the Runtime.getRuntime().maxMemory() or Runtime.getRunetime.totalmemory() methods, depending on your needs.

Mikkel Løkke
  • 3,710
  • 23
  • 37