Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/399.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 对于Runtime.getRuntime().gc()是否有任何副作用_Java_Performance_Coding Style_Garbage Collection_Runtime - Fatal编程技术网

Java 对于Runtime.getRuntime().gc()是否有任何副作用

Java 对于Runtime.getRuntime().gc()是否有任何副作用,java,performance,coding-style,garbage-collection,runtime,Java,Performance,Coding Style,Garbage Collection,Runtime,我想知道在我们的程序中显式使用Runtime.getRuntime().gc()是否有任何副作用 或者使用相同的代码以获得更好的性能是一种良好的做法 即使使用Runtime.getRuntime().gc(),也不能保证内存是可用的Runtime.getRuntime().gc()可能会导致副作用 Runtime.getRuntime().gc()-不保证gc将运行 Runtime.getRuntime().gc()-如文档所述,这将提示gc它可以执行操作,如果gc决定准备运行,则可能与应用程序

我想知道在我们的程序中显式使用
Runtime.getRuntime().gc()
是否有任何副作用


或者使用相同的代码以获得更好的性能是一种良好的做法

即使使用Runtime.getRuntime().gc(),也不能保证内存是可用的

Runtime.getRuntime().gc()
可能会导致副作用

  • Runtime.getRuntime().gc()
    -不保证gc将运行

  • Runtime.getRuntime().gc()
    -如文档所述,这将提示gc它可以执行操作,如果gc决定准备运行,则可能与应用程序处理线程重叠,并导致延迟和缓慢


  • 建议不要使用此选项,而是尝试调试GC以使系统正常运行。

    每次使用
    Runtime.getRuntime().GC()
    时,您的程序可能会缓慢运行。

    是的,不保证JVM会调用垃圾收集器。我们无法预测。JVM将在内存几乎满时收集数据,这是肯定的。