同一个方法中的被synchronized包裹的代码块与普通代码块
public class SynchronizedCodeblock implements Runnable{
static SynchronizedCodeblock instance1 = new SynchronizedCodeblock();
//static SynchronizedCodeblock instance2 = new SynchronizedCodeblock();
static int i = 0;
public static void main(String[] args) {
Thread t1 = new Thread(instance1);
Thread t2 = new Thread(instance1);
t1.start();
t2.start();
while(t1.isAlive() || t2.isAlive() ) {}
System.err.println(i);
System.err.println("finished!");
}
public void run() {
method();
}
public void method() {
//synchronized(SynchronizedCodeblock.class) {
synchronized(this) {
System.err.println("我是同步块内代码,我叫:"+Thread.currentThread().getName());
for (int j = 0; j < 10000; j++)
        {
System.err.println(Thread.currentThread().getName() +": " + i++);
        }
System.err.println("同步块内代码运行结束,我叫:"+Thread.currentThread().getName());
}
System.err.println("我是同步块外代码,我叫:"+Thread.currentThread().getName());
for (int j = 0; j < 100000; j++)
        {
System.err.println(Thread.currentThread().getName() +": " + i++);
        }
System.err.println("同步块外代码运行结束,我叫:"+Thread.currentThread().getName());
}
}结果:
。。。
Thread-1: 219984
Thread-1: 219985
Thread-1: 219986
同步块外代码运行结束,我叫:Thread-1
219987
finished!
我不太明白,当某个线程执行到ssynchronized代码块发现拿不到锁时,该线程会跳过这端代码,然后执行下面的代码吗,如果是这样,我就不理解了,这两块代码都在一个线程,为什么不会顺序执行呢,jvm做了什么,迷惑,求教?