本文整理了Java中java.lang.System.runFinalization()
方法的一些代码示例,展示了System.runFinalization()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。System.runFinalization()
方法的具体详情如下:
包路径:java.lang.System
类名称:System
方法名:runFinalization
[英]Provides a hint to the VM that it would be useful to attempt to perform any outstanding object finalization.
[中]向VM提供一个提示,提示尝试执行任何未完成的对象终结将非常有用。
代码示例来源: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;
}
}
}
内容来源于网络,如有侵权,请联系作者删除!