从图片中 对象头从 001到000再到001,从无锁跳到了轻量级锁,只有一个线程访问锁的话不是先变成偏向锁的吗?
public class SynchronizedLockInfoTest {
private static Object object = new Object();
public static void main(String[] args) {
System.out.println(object.toString());
SynchronizedLockInfoTest synchronizedLockInfoTest = new SynchronizedLockInfoTest();
Thread1 thread1 = synchronizedLockInfoTest.new Thread1();
thread1.start();
}
public class Thread1 extends Thread{
@Override
public void run() {
Thread thread = Thread.currentThread();
System.out.println(1);
System.out.println(thread.getName() + ClassLayout.parseInstance(object).toPrintable());
synchronized (object){
System.out.println(2);
System.out.println(thread.getName() + ClassLayout.parseInstance(object).toPrintable());
}
System.out.println(3);
System.out.println(thread.getName() + ClassLayout.parseInstance(object).toPrintable());
}
}
}