public class StackAllocation {
public static void main(String[] args) {
long start = System.currentTimeMillis();
for (int i = 0; i < 10000000; i++) {
alloc();
}
// 查看執行時間
long end = System.currentTimeMillis();
System.out.println("花費的時間為: " + (end - start) + " ms");
// 為了方便查看堆記憶體中物件個數,執行緒sleep
try {
Thread.sleep(1000000);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
private static void alloc() {
User user = new User();//未發生逃逸
}
static class User {
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/284317.html
標籤:Java相關
