java - Does periodic garbage collection help JVM performance? -
i encountered following code (slightly simplified):
/* periodically requests garbagecollect improve memory usage , garbage collect performance under jvms */ static class gcthread implements runnable { public void run() { while(true) { try { thread.sleep(300000); } catch (interruptedexception e) {} system.gc(); } } } thread gcthread = new thread(new gcthread()); gcthread.setdaemon(true); gcthread.start();
i respect author of code, no longer has easy access ask him defend assertion in comment on top.
is true? goes against intuition little hack should improve anything. expect jvm better equipped decide when perform collection.
the code running in web-application running inside ibm websphere on z/os.
it depends.
the jvm can ignore
system.gc()
code absolutely nothing.secondly, gc has cost impact. if program wouldn't otherwise have done gc (say, doesn't generate garbage, or has huge heap , never needs gc) code add overhead.
if program run minor gcs , code causes major gc, have negative impact.
all in all, kind of optimisation makes absolutely no sense whatsoever unless have concrete evidence provides benefit , need re-evaluate evidence every time program materially changed.
Comments
Post a Comment