JAVA 大数据内存耗用测试
import java.lang.management.ManagementFactory;
import java.lang.management.MemoryMXBean;
public class MemoryTest {
public static void main(String[] args) throws InterruptedException {
int row = 50_000;
int column = 20;
String[] data = new String[row * column];
for (int i = 0; i < data.length; i++) {
data[i] = "columnName" + (i % column);
}
while (true) {
int i = (int) (Math.random() % (row * column));
if (data[i] == data[(i + column) % (row * column)]) {
System.out.println("the seme object");
}
System.gc();
MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
long used = memoryMXBean.getHeapMemoryUsage().getUsed();
System.out.println("used:" + used / 1024d /1024d);
Thread.sleep(10_000);
}
}
}