optimized memory used

This commit is contained in:
wenshao
2012-10-08 09:27:08 +08:00
parent 5088fa8a34
commit f551328636
10 changed files with 451 additions and 231 deletions
@@ -0,0 +1,38 @@
package com.alibaba.druid.stat;
import java.lang.management.ManagementFactory;
import java.text.NumberFormat;
import java.util.concurrent.atomic.AtomicLong;
import junit.framework.TestCase;
public class MemoryTest extends TestCase {
public void test_0() throws Exception {
A item = new A();
gc();
final int COUNT = 1024 * 1024;
A[] items = new A[COUNT];
long memoryStart = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed();
for (int i = 0; i < COUNT; ++i) {
items[i] = new A();
// items[i] = Histogram.makeHistogram(20);
}
long memoryEnd = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed();
System.out.println("memory used : " + NumberFormat.getInstance().format(memoryEnd - memoryStart));
}
private void gc() {
for (int i = 0; i < 10; ++i) {
System.gc();
}
}
public static class A {
private volatile long v;
}
}