并发系列—JOL

JOL:Java Object Layout,是一款工具,可以帮助我们查看对象的内存信息。

1、pom.xml


   org.openjdk.jol
   jol-core
   0.9

2、java中使用jol获取对象内存信息

public static void main(String[] args) throws Exception{
        AtomicInteger atomicInteger = new AtomicInteger();
        System.out.println(ClassLayout.parseInstance(atomicInteger).toPrintable());
        System.out.println("初始值:"+atomicInteger.get());
        System.out.println(ClassLayout.parseInstance(atomicInteger).toPrintable());
        synchronized (atomicInteger){
            System.out.println(ClassLayout.parseInstance(atomicInteger).toPrintable());
            atomicInteger.incrementAndGet();
            System.out.println("当前值:"+atomicInteger.get());
        }
        System.out.println(ClassLayout.parseInstance(atomicInteger).toPrintable());
       
 }

并发系列—JOL_第1张图片

你可能感兴趣的:(锁,JOL)