public void start() {
label0: {
synchronized(running) {
if(!running.booleanValue())
break label0;
position = 0;
repeatsLeft = repeatCount;
}
return;
}
animationThread = new Thread(new Runnable() { public void run() {
runAnimation();
}
});
animationThread.start();
running = Boolean.valueOf(true);
boolean1;
JVM INSTR monitorexit ;
}
我知道好像是个反编译。
1.提问:label0作用?最后两行的作用?
label0: {
synchronized(running) {
if(!running.booleanValue())
break label0;
position = 0;
repeatsLeft = repeatCount;
}
return;
}
animationThread = new Thread(new Runnable() { public void run() {
runAnimation();
}
});
animationThread.start();
running = Boolean.valueOf(true);
boolean1;
JVM INSTR monitorexit ;
}
我知道好像是个反编译。
1.提问:label0作用?最后两行的作用?
1)label0作用:标识这个{...}所标识的组语句.当running值为false时(表示还没有:处于运行中),则break跳出这个语句块(执行下边的语句:即创建animationThread 线程并运行它.)
2)JVM INSTR monitorexit 作用:由于running是一个临界区(因为已用synchronized(running)),而且当running值为false时,直接用break跳出了synchronized()代码块,此时running的对象锁还没有被释放.此句的作用是:释放synchronized的对象锁(释放对象的操作语句是由编译器自动加的).
除了此处,在" repeatsLeft =repeatCount; "语句之后(即synchronized代码块结束处),也自动释放对象锁.