English 中文(简体)
Setting JVM parameters at runtime
原标题:
  • 时间:2009-11-18 06:38:18
  •  标签:
  • java
  • jvm
  • ikvm

Is it possible to change/modify/adding VM parameters after the JVM is already loaded (running)? If so, how can I do it?

最佳回答

For properties you d set via the -D flag on the command line, you want System.setProperty. For example:

System.setProperty("propname", "hello world");

// ... later ...
String value = System.getProperty("propname");

Update:

You can t enable debugging dynamically, but you can enable debugging at startup but attach a debugger later. With the following, you can listen on port 12345 and start your program running right away (via suspend=n). Then you can attach a debugger if/when you need to, detach the debugger, attach again later, etc.

-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=12345

Of course, this hurts performance even when the debugger isn t attached, so it only works well in dev/test code, not production. For that, you want logging, e.g. log4j.

问题回答

A short answer is that you cannot change VM parameters at runtime. The Runtime class does expose some options such max memory. The main parameters such as max memory should only be set by an admin type allowing management of resources when multiple JVMs co exist on a machine. Allowing one JVM to get greedy and ask for lots and lots more than it was allocated would kill this constraint.





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签