1

i am interested to write a java program to perform GC on another JVm which present in the another machine. 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

krishna
  • 11
  • 1
  • 2
    Just don't. Leave garbage collection to garbage collector. You cannot help doing GC manually - you can only interfere. – Rekin Dec 22 '10 at 08:14

2 Answers2

3

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.

Community
  • 1
  • 1
Steven Schlansker
  • 34,307
  • 13
  • 76
  • 99
0

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