Tabnine Logo
System.runFinalization
Code IndexAdd Tabnine to your IDE (free)

How to use
runFinalization
method
in
java.lang.System

Best Java code snippets using java.lang.System.runFinalization (Showing top 20 results out of 1,566)

origin: square/okhttp

 /**
  * See FinalizationTester for discussion on how to best trigger GC in tests.
  * https://android.googlesource.com/platform/libcore/+/master/support/src/test/java/libcore/
  * java/lang/ref/FinalizationTester.java
  */
 public static void awaitGarbageCollection() throws Exception {
  Runtime.getRuntime().gc();
  Thread.sleep(100);
  System.runFinalization();
 }
}
origin: btraceio/btrace

  /**
   * Runs the finalization methods of any objects pending finalization.
   * <p>
   * Calling this method suggests that the Java Virtual Machine expend
   * effort toward running the <code>finalize</code> methods of objects
   * that have been found to be discarded but whose <code>finalize</code>
   * methods have not yet been run. When control returns from the
   * method call, the Java Virtual Machine has made a best effort to
   * complete all outstanding finalizations. This method calls
   * Sys.runFinalization() to run finalization.
   */
  public static void runFinalization() {
    java.lang.System.runFinalization();
  }
}
origin: fengjiachun/Jupiter

public static void runFinalization() {
  System.runFinalization();
}
origin: fengjiachun/Jupiter

public static void runFinalization() {
  System.runFinalization();
}
origin: square/leakcanary

@Override public void runGc() {
 // Code taken from AOSP FinalizationTest:
 // https://android.googlesource.com/platform/libcore/+/master/support/src/test/java/libcore/
 // java/lang/ref/FinalizationTester.java
 // System.gc() does not garbage collect every time. Runtime.gc() is
 // more likely to perform a gc.
 Runtime.getRuntime().gc();
 enqueueReferences();
 System.runFinalization();
}
origin: robovm/robovm

/**
 * This method exists for binary compatibility.  It is equivalent
 * to {@link System#runFinalization}.
 */
@Deprecated
public void runFinalizationSync() {
  System.runFinalization();
}
origin: thinkaurelius/titan

  private static void collectGarbage() {
    try {
      System.gc();
      Thread.sleep(fSLEEP_INTERVAL);
      System.runFinalization();
      Thread.sleep(fSLEEP_INTERVAL);
    } catch (InterruptedException ex) {
      ex.printStackTrace();
    }
  }
}
origin: JanusGraph/janusgraph

  private static void collectGarbage() {
    try {
      System.gc();
      Thread.sleep(fSLEEP_INTERVAL);
      System.runFinalization();
      Thread.sleep(fSLEEP_INTERVAL);
    } catch (InterruptedException ex) {
      ex.printStackTrace();
    }
  }
}
origin: objectbox/objectbox-java

/** Also retries up to 500ms to improve GC race condition situation. */
private static boolean isFileOpen(String canonicalPath) {
  synchronized (openFiles) {
    int tries = 0;
    while (tries < 5 && openFiles.contains(canonicalPath)) {
      tries++;
      System.gc();
      System.runFinalization();
      System.gc();
      System.runFinalization();
      try {
        openFiles.wait(100);
      } catch (InterruptedException e) {
        // Ignore
      }
    }
    return openFiles.contains(canonicalPath);
  }
}
origin: google/guava

/**
 * Waits until the given latch has {@linkplain CountDownLatch#countDown counted down} to zero,
 * invoking the garbage collector as necessary to try to ensure that this will happen.
 *
 * @throws RuntimeException if timed out or interrupted while waiting
 */
public static void await(CountDownLatch latch) {
 if (latch.getCount() == 0) {
  return;
 }
 final long timeoutSeconds = timeoutSeconds();
 final long deadline = System.nanoTime() + SECONDS.toNanos(timeoutSeconds);
 do {
  System.runFinalization();
  if (latch.getCount() == 0) {
   return;
  }
  System.gc();
  try {
   if (latch.await(1L, SECONDS)) {
    return;
   }
  } catch (InterruptedException ie) {
   throw new RuntimeException("Unexpected interrupt while waiting for latch", ie);
  }
 } while (System.nanoTime() - deadline < 0);
 throw formatRuntimeException(
   "Latch failed to count down within %d second timeout", timeoutSeconds);
}
origin: google/guava

final long deadline = System.nanoTime() + SECONDS.toNanos(timeoutSeconds);
do {
 System.runFinalization();
 if (future.isDone()) {
  return;
origin: google/guava

System.runFinalization();
origin: Netflix/eureka

  public static void gc() {
    System.gc();
    System.runFinalization();
    try {
      Thread.sleep(1000);
    } catch (InterruptedException e) {
      // IGNORE
    }
  }
}
origin: ehcache/ehcache3

@SuppressFBWarnings("DM_GC")
static boolean tryRecursiveDelete(File file) {
 boolean interrupted = false;
 try {
  for (int i = 0; i < 5; i++) {
   if (recursiveDelete(file) || !isWindows()) {
    return true;
   } else {
    System.gc();
    System.runFinalization();
    try {
     Thread.sleep(50);
    } catch (InterruptedException e) {
     interrupted = true;
    }
   }
  }
 } finally {
  if (interrupted) {
   Thread.currentThread().interrupt();
  }
 }
 return false;
}
origin: google/guava

/**
 * Waits until the given predicate returns true, invoking the garbage collector as necessary to
 * try to ensure that this will happen.
 *
 * @throws RuntimeException if timed out or interrupted while waiting
 */
public static void awaitDone(FinalizationPredicate predicate) {
 if (predicate.isDone()) {
  return;
 }
 final long timeoutSeconds = timeoutSeconds();
 final long deadline = System.nanoTime() + SECONDS.toNanos(timeoutSeconds);
 do {
  System.runFinalization();
  if (predicate.isDone()) {
   return;
  }
  CountDownLatch done = new CountDownLatch(1);
  createUnreachableLatchFinalizer(done);
  await(done);
  if (predicate.isDone()) {
   return;
  }
 } while (System.nanoTime() - deadline < 0);
 throw formatRuntimeException(
   "Predicate did not become true within %d second timeout", timeoutSeconds);
}
origin: ben-manes/caffeine

/**
 * Runs all JSR166 unit tests using junit.textui.TestRunner.
 * Optional command line arg provides the number of iterations to
 * repeat running the tests.
 */
public static void main(String[] args) {
  if (useSecurityManager) {
    System.err.println("Setting a permissive security manager");
    Policy.setPolicy(permissivePolicy());
    System.setSecurityManager(new SecurityManager());
  }
  int iters = (args.length == 0) ? 1 : Integer.parseInt(args[0]);
  Test s = suite();
  for (int i = 0; i < iters; ++i) {
    junit.textui.TestRunner.run(s);
    System.gc();
    System.runFinalization();
  }
  System.exit(0);
}
origin: jtablesaw/tablesaw

/**
 * Call GC until no more memory can be freed
 */
public static void restoreJvm() {
  int maxRestoreJvmLoops = 10;
  long memUsedPrev = memoryUsed();
  for (int i = 0; i < maxRestoreJvmLoops; i++) {
    System.runFinalization();
    System.gc();
    long memUsedNow = memoryUsed();
    // break early if have no more finalization and get constant mem used
    if ((ManagementFactory.getMemoryMXBean().getObjectPendingFinalizationCount() == 0) && (memUsedNow
        >= memUsedPrev)) {
      break;
    } else {
      memUsedPrev = memUsedNow;
    }
  }
}
origin: geoserver/geoserver

protected final void tearDown(SystemTestData testData) throws Exception {
  if (testData.isTestDataAvailable()) {
    onTearDown(testData);
    destroyGeoServer();
    TestHttpClientProvider.endTest();
    // some tests do need a kick on the GC to fully clean up
    if (isMemoryCleanRequired()) {
      System.gc();
      System.runFinalization();
    }
  }
}
origin: objectbox/objectbox-java

@After
public void tearDown() throws Exception {
  // Collect dangling Cursors and TXs before store closes
  System.gc();
  System.runFinalization();
  if (store != null) {
    try {
      store.close();
      store.deleteAllFiles();
      File[] files = boxStoreDir.listFiles();
      if (files != null) {
        for (File file : files) {
          logError("File was not deleted: " + file.getAbsolutePath());
        }
      }
    } catch (Exception e) {
      logError("Could not clean up test", e);
    }
  }
  deleteAllFiles();
}
origin: geoserver/geoserver

/** If subclasses overide they *must* call super.tearDown() first. */
@Override
protected void oneTimeTearDown() throws Exception {
  if (getTestData().isTestDataAvailable()) {
    try {
      // dispose WFS XSD schema's - they will otherwise keep geoserver instance alive
      // forever!!
      disposeIfExists(getXSD11());
      disposeIfExists(getXSD10());
      // kill the context
      applicationContext.destroy();
      // kill static caches
      GeoServerExtensionsHelper.init(null);
      // some tests do need a kick on the GC to fully clean up
      if (isMemoryCleanRequired()) {
        System.gc();
        System.runFinalization();
      }
      if (getTestData() != null) {
        getTestData().tearDown();
      }
    } finally {
      applicationContext = null;
      testData = null;
    }
  }
}
java.langSystemrunFinalization

Javadoc

Provides a hint to the VM that it would be useful to attempt to perform any outstanding object finalization.

Popular methods of System

  • currentTimeMillis
    Returns the current time in milliseconds. Note that while the unit of time of the return value is a
  • getProperty
    Returns the value of a particular system property. The defaultValue will be returned if no such prop
  • arraycopy
  • exit
  • setProperty
    Sets the value of a particular system property.
  • nanoTime
    Returns the current timestamp of the most precise timer available on the local system, in nanosecond
  • getenv
    Returns the value of the environment variable with the given name, or null if no such variable exist
  • getProperties
    Returns the system properties. Note that this is not a copy, so that changes made to the returned Pr
  • identityHashCode
    Returns an integer hash code for the parameter. The hash code returned is the same one that would be
  • getSecurityManager
    Gets the system security interface.
  • gc
    Indicates to the VM that it would be a good time to run the garbage collector. Note that this is a h
  • lineSeparator
    Returns the system's line separator. On Android, this is "\n". The value comes from the value of the
  • gc,
  • lineSeparator,
  • clearProperty,
  • setOut,
  • setErr,
  • console,
  • loadLibrary,
  • load,
  • setSecurityManager,
  • mapLibraryName

Popular in Java

  • Finding current android device location
  • addToBackStack (FragmentTransaction)
  • getSystemService (Context)
  • setContentView (Activity)
  • URLConnection (java.net)
    A connection to a URL for reading or writing. For HTTP connections, see HttpURLConnection for docume
  • Date (java.util)
    A specific moment in time, with millisecond precision. Values typically come from System#currentTime
  • Hashtable (java.util)
    A plug-in replacement for JDK1.5 java.util.Hashtable. This version is based on org.cliffc.high_scale
  • Map (java.util)
    A Map is a data structure consisting of a set of keys and values in which each key is mapped to a si
  • Random (java.util)
    This class provides methods that return pseudo-random values.It is dangerous to seed Random with the
  • JPanel (javax.swing)
  • From CI to AI: The AI layer in your organization
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now