java.lang.Runtime.runFinalization()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(5.7k)|赞(0)|评价(0)|浏览(166)

本文整理了Java中java.lang.Runtime.runFinalization()方法的一些代码示例,展示了Runtime.runFinalization()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Runtime.runFinalization()方法的具体详情如下:
包路径:java.lang.Runtime
类名称:Runtime
方法名:runFinalization

Runtime.runFinalization介绍

[英]Provides a hint to the VM that it would be useful to attempt to perform any outstanding object finalization.
[中]向VM提供一个提示,提示尝试执行任何未完成的对象终结将非常有用。

代码示例

代码示例来源:origin: robovm/robovm

  1. /**
  2. * Provides a hint to the VM that it would be useful to attempt
  3. * to perform any outstanding object finalization.
  4. */
  5. public static void runFinalization() {
  6. Runtime.getRuntime().runFinalization();
  7. }

代码示例来源:origin: osmandapp/Osmand

  1. protected static long runGCUsedMemory() {
  2. Runtime runtime = Runtime.getRuntime();
  3. long usedMem1 = runtime.totalMemory() - runtime.freeMemory();
  4. long usedMem2 = Long.MAX_VALUE;
  5. int cnt = 4;
  6. while (cnt-- >= 0) {
  7. for (int i = 0; (usedMem1 < usedMem2) && (i < 1000); ++i) {
  8. // AVIAN FIXME
  9. runtime.runFinalization();
  10. runtime.gc();
  11. Thread.yield();
  12. usedMem2 = usedMem1;
  13. usedMem1 = runtime.totalMemory() - runtime.freeMemory();
  14. }
  15. }
  16. return usedMem1;
  17. }

代码示例来源:origin: com.h2database/h2

  1. /**
  2. * Call the garbage collection and run finalization. This close all files
  3. * that were not closed, and are no longer referenced.
  4. */
  5. static void freeMemoryAndFinalize() {
  6. IOUtils.trace("freeMemoryAndFinalize", null, null);
  7. Runtime rt = Runtime.getRuntime();
  8. long mem = rt.freeMemory();
  9. for (int i = 0; i < 16; i++) {
  10. rt.gc();
  11. long now = rt.freeMemory();
  12. rt.runFinalization();
  13. if (now == mem) {
  14. break;
  15. }
  16. mem = now;
  17. }
  18. }

代码示例来源:origin: lealone/Lealone

  1. /**
  2. * Call the garbage collection and run finalization. This close all files
  3. * that were not closed, and are no longer referenced.
  4. */
  5. static void freeMemoryAndFinalize() {
  6. IOUtils.trace("freeMemoryAndFinalize", null, null);
  7. Runtime rt = Runtime.getRuntime();
  8. long mem = rt.freeMemory();
  9. for (int i = 0; i < 16; i++) {
  10. rt.gc();
  11. long now = rt.freeMemory();
  12. rt.runFinalization();
  13. if (now == mem) {
  14. break;
  15. }
  16. mem = now;
  17. }
  18. }

代码示例来源:origin: robovm/robovm

  1. runFinalization();

代码示例来源:origin: stackoverflow.com

  1. Runtime runtime = Runtime.getRuntime();
  2. for (int i = 0; i < MAX_GC_ITERATIONS; i++) {
  3. runtime.runFinalization();
  4. runtime.gc();
  5. if (getObject() == null)

代码示例来源:origin: psi-probe/psi-probe

  1. @Override
  2. protected ModelAndView handleRequestInternal(HttpServletRequest request,
  3. HttpServletResponse response) throws Exception {
  4. boolean finalization = ServletRequestUtils.getBooleanParameter(request, "fin", false);
  5. String referer = request.getHeader("Referer");
  6. String redirectUrl;
  7. if (referer != null) {
  8. redirectUrl = referer.replaceAll(replacePattern, "");
  9. } else {
  10. redirectUrl = request.getContextPath() + getViewName();
  11. }
  12. if (finalization) {
  13. Runtime.getRuntime().runFinalization();
  14. logger.debug("Advised finalization");
  15. } else {
  16. Runtime.getRuntime().gc();
  17. logger.debug("Advised Garbage Collection");
  18. }
  19. logger.debug("Redirected to {}", redirectUrl);
  20. return new ModelAndView(new RedirectView(redirectUrl));
  21. }

代码示例来源:origin: geotools/geotools

  1. @BeforeClass
  2. public static void setupOnce() {
  3. // isolate this test from previously run ones that might have left undisposed map contents
  4. System.gc();
  5. Runtime.getRuntime().runFinalization();
  6. }

代码示例来源:origin: MobiVM/robovm

  1. /**
  2. * Provides a hint to the VM that it would be useful to attempt
  3. * to perform any outstanding object finalization.
  4. */
  5. public static void runFinalization() {
  6. Runtime.getRuntime().runFinalization();
  7. }

代码示例来源:origin: ibinti/bugvm

  1. /**
  2. * Provides a hint to the VM that it would be useful to attempt
  3. * to perform any outstanding object finalization.
  4. */
  5. public static void runFinalization() {
  6. Runtime.getRuntime().runFinalization();
  7. }

代码示例来源:origin: com.mobidevelop.robovm/robovm-rt

  1. /**
  2. * Provides a hint to the VM that it would be useful to attempt
  3. * to perform any outstanding object finalization.
  4. */
  5. public static void runFinalization() {
  6. Runtime.getRuntime().runFinalization();
  7. }

代码示例来源:origin: Audiveris/audiveris

  1. /**
  2. * 'Suggest' to run the garbage collector.
  3. * Note this does not call the garbage collector synchronously.
  4. */
  5. public static void gc ()
  6. {
  7. rt.runFinalization();
  8. rt.gc();
  9. }

代码示例来源:origin: com.bugvm/bugvm-rt

  1. /**
  2. * Provides a hint to the VM that it would be useful to attempt
  3. * to perform any outstanding object finalization.
  4. */
  5. public static void runFinalization() {
  6. Runtime.getRuntime().runFinalization();
  7. }

代码示例来源:origin: mercyblitz/thinking-in-spring-boot-samples

  1. public static void main(String[] args) {
  2. Runtime runtime = Runtime.getRuntime();
  3. // 注册 Shutdown Hook
  4. runtime.addShutdownHook(new Thread(() -> {
  5. System.out.println("Shutdown Hook 执行...");
  6. }));
  7. runtime.runFinalization();
  8. System.exit(0);
  9. }

代码示例来源:origin: com.uphyca/android-junit4

  1. private static void stopAllocCounting() {
  2. Runtime.getRuntime().gc();
  3. Runtime.getRuntime().runFinalization();
  4. Runtime.getRuntime().gc();
  5. Debug.stopAllocCounting();
  6. }

代码示例来源:origin: com.uphyca/android-junit4

  1. private static void startAllocCounting() {
  2. // Before we start trigger a GC and reset the debug counts. Run the
  3. // finalizers and another GC before starting and stopping the alloc
  4. // counts. This will free up any objects that were just sitting around
  5. // waiting for their finalizers to be run.
  6. Runtime.getRuntime().gc();
  7. Runtime.getRuntime().runFinalization();
  8. Runtime.getRuntime().gc();
  9. Debug.resetAllCounts();
  10. // start the counts
  11. Debug.startAllocCounting();
  12. }

代码示例来源:origin: geotools/geotools

  1. grabLogger(Level.SEVERE);
  2. renderAndStop(content, bounds);
  3. Runtime.getRuntime().runFinalization();
  4. String messages = getLogOutput();
  5. assertThat(

代码示例来源:origin: net.sourceforge.owlapi/pellet-core-ignazio1977

  1. private static void _runGC () throws Exception
  2. {
  3. long usedMem1 = usedMemory (), usedMem2 = Long.MAX_VALUE;
  4. for (int i = 0; (usedMem1 < usedMem2) && (i < 500); ++ i)
  5. {
  6. runtime.runFinalization();
  7. runtime.gc();
  8. Thread.yield();
  9. usedMem2 = usedMem1;
  10. usedMem1 = usedMemory();
  11. }
  12. }

代码示例来源:origin: vmware/xenon

  1. public void waitForGC() {
  2. if (!isStressTest()) {
  3. return;
  4. }
  5. for (int k = 0; k < 10; k++) {
  6. Runtime.getRuntime().gc();
  7. Runtime.getRuntime().runFinalization();
  8. }
  9. }

代码示例来源:origin: com.vmware.xenon/xenon-common

  1. public void waitForGC() {
  2. if (!isStressTest()) {
  3. return;
  4. }
  5. for (int k = 0; k < 10; k++) {
  6. Runtime.getRuntime().gc();
  7. Runtime.getRuntime().runFinalization();
  8. }
  9. }

相关文章