I am interested to retrieve the java process from the task manager & perform开发者_如何学C GC based on the memory...
Can you provide any information to achieve it
Thanks & regards, Krishna
Here is a description on how to get the current used memory:
http://viralpatel.net/blogs/2009/05/getting-jvm-heap-size-used-memory-total-memory-using-java-runtime.html
The Garbage Collector you can trigger by calling:
System.gc()
see: http://download.oracle.com/javase/1.4.2/docs/api/java/lang/System.html#gc%28%29 For a documentation
As far as I understand you wish to perform these operations on external process (retrieve the java process from the task manager
).
I'd suggest you to check out JMX. This is the "normal" way to do it remotely. If JConsole does it you can implement it yourself too.
You have to use java.lang.management.GarbageCollectorMXBean
精彩评论