JAVA 大数据内存耗用测试

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);
}
}
}

上一篇:Linux命令行上执行操作,不退回命令行的解决方法


下一篇:Java中的四种引用类型,强引用,软引用,弱引用,虚引用