开发者

RMI program to preform GC on another JVM

开发者 https://www.devze.com 2023-01-31 13:34 出处:网络
i am interested to write a java program to perform GC on another JVm which present in the another machi开发者_开发知识库ne. Presently i am monitoring the JVM manually means i am opening jconsole in my

i am interested to write a java program to perform GC on another JVm which present in the another machi开发者_开发知识库ne. Presently i am monitoring the JVM manually means i am opening jconsole in my machine & preform GC when the JVM memory croses particular memory limit. i want to do automatically by java program..

please provide suggestions....

Thanks, Krishna


This sounds like a terrible hack to deal with a problem almost certainly unrelated to the garbage collector itself. Forcing full garbage collection is almost never what you want to do. There's multiple threads on stackoverflow about it, such as Why is it a bad practice to call System.gc()?

The short answer is, don't do that. Tune your GC options to make it do what you want instead.

If you have evaluated all other options and still want to go down this path of sadness, you could just have an RMI method invoke System.gc() as Mr. Flamer suggests. If you really really want to be sure, use the JVMTI ForceGarbageCollection method.


But remember when you call System.gc() it is not guaranteed to start garbagecollection. You should leave this to the JVM.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号