Skip to content

Instantly share code, notes, and snippets.

@jonasurbano jonasurbano/GCing.java Secret
Created Apr 1, 2016

Embed
What would you like to do?
public class GCing {
private static final int k = 1024;
private static final int m = k * k;
private static final int MAX_ITERATIONS = 10;
private static final int DEFAULT_SIZE = 640;
private static int iterations = 1;
private byte[] bytes;
public static void main(String[] args) throws InterruptedException {
int size = sizeFromArgumentsOrDefault(args);
System.err.println("Size is " + size + " MB");
while (condition()) {
process(size);
}
}
private static void process(int size) {
long milis = System.currentTimeMillis();
GCing gcing1 = new GCing(size * m);
System.err.println("Milis: " + (System.currentTimeMillis() - milis));
}
private static boolean condition() {
return iterations++ <= MAX_ITERATIONS;
}
private static int sizeFromArgumentsOrDefault(String[] args) {
if (args == null || args.length == 0)
return DEFAULT_SIZE;
int size = DEFAULT_SIZE;
try {
size = Integer.parseInt(args[0]);
} catch (Exception exception) {
}
if (size < 0)
return DEFAULT_SIZE;
return size;
}
public GCing(int size) {
bytes = new byte[size];
}
public byte[] getBytes() {
return bytes;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.