Skip to content

Instantly share code, notes, and snippets.

@tom-lpsd
Last active September 16, 2016 17:20
Show Gist options
  • Save tom-lpsd/8ac86e645c94ddcd9e76 to your computer and use it in GitHub Desktop.
Save tom-lpsd/8ac86e645c94ddcd9e76 to your computer and use it in GitHub Desktop.
java -verbose:gc -XX:+PrintGCDetails -XX:+PrintPromotionFailure -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:+PrintGCDateStamps -Xmx1g -Xms1g -Xmn100m -XX:CMSInitiatingOccupancyFraction=99 GC 2000000
import java.util.Random;
public class GC {
static class Foo {
byte[] raw;
public Foo(int n) {
raw = new byte[n];
}
}
private void busyWait(int n) {
int sum = 0;
for (int i = 0; i < n * 1000; i++) {
sum += (i * i - i);
}
if (sum == n) {
System.out.println(sum);
}
}
private void fill(int max, int unit, Foo[] f1, Foo[] f2) {
for (int i = 0; i < max * 2; i++) {
switch (i % 2){
case 0:
f1[(int)(i/2)] = new Foo(unit);
break;
case 1:
f2[(int)(i/2)] = new Foo(unit);
break;
}
busyWait(4);
}
System.out.println("fill done ================================================================");
}
public void run(int max) {
Thread th = new Thread() {
@Override
public void run() {
while (true) {
System.out.println(System.currentTimeMillis());
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
}
}
};
th.setDaemon(true);
th.start();
Foo[] f1 = new Foo[max];
Foo[] f2 = new Foo[max];
fill(max, 100, f1, f2);
f2 = new Foo[max];
Foo[] f3 = new Foo[max];
fill(max, 110, f2, f3);
f3 = new Foo[max];
Foo[] f4 = new Foo[max];
fill(max, 120, f2, f3);
System.out.println("done!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
}
public static void main(String[] args) throws Exception {
int max = Integer.parseInt(args[0]);
System.out.println(max);
new GC().run(max);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment