How to retrieve useful system information in java?

Which system information are useful - especially when tracing an exception or other problems down - in a java application?

I am thinking about details about exceptions, java/os information, memory/object consumptions, io information, environment/enchodings etc.


Besides the obvious - the exception stack trace - the more info you can get is better. So you should get all the system properties as well as environment variables. Also if your application have some settings, get all their values. Of course you should put all this info into your log file, I used System.out her for simplicity:

System.out.println("----Java System Properties----");       
System.getProperties().list(System.out);

System.out.println("----System Environment Variables----");
Map<String, String> env = System.getenv();
Set<String> keys = env.keySet();
for (String key : keys) {
    System.out.println(key + "=" + env.get(key));
}

For most cases this will be "too much" information, but for most cases the stack trace will be enough. Once you will get a tough issue you will be happy that you have all that "extra" information


查看Javadoc for System.getProperties() ,它记录了每个JVM中保证存在的属性。


对于纯Java应用程序:

System.getProperty("org.xml.sax.driver") 
System.getProperty("java.version")
System.getProperty("java.vm.version")
System.getProperty("os.name")
System.getProperty("os.version")
System.getProperty("os.arch")
链接地址: http://www.djcxy.com/p/2304.html

上一篇: opengl矩阵旋转四元数

下一篇: 如何在java中检索有用的系统信息?