Add Miscellaneous#invokeGarbageCollector method
This commit is contained in:
parent
a6e83a25eb
commit
c66a780b78
1 changed files with 14 additions and 0 deletions
|
@ -21,6 +21,8 @@ package de.staropensource.sosengine.base.utility;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.lang.ref.WeakReference;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains smaller functions that don't fit into other utility classes.
|
* Contains smaller functions that don't fit into other utility classes.
|
||||||
*
|
*
|
||||||
|
@ -47,4 +49,16 @@ public class Miscellaneous {
|
||||||
public static String padNumbers(long number, int length) {
|
public static String padNumbers(long number, int length) {
|
||||||
return String.format("%0" + length + "d", number);
|
return String.format("%0" + length + "d", number);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Forcefully invokes the garbage collector and blocks execution until finished.
|
||||||
|
*
|
||||||
|
* @since 1-alpha0
|
||||||
|
*/
|
||||||
|
public static void invokeGarbageCollector() {
|
||||||
|
Object object = new Object();
|
||||||
|
WeakReference<Object> weakReference = new WeakReference<>(object);
|
||||||
|
object = null;
|
||||||
|
while(weakReference.get() != null) System.gc();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue