public class Test implements Runnable
{
Integer i = 100;
@Override
public void run() {
while (true)
{
synchronized (this) {
if (i>0)
{
try {
Thread.sleep(20);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(Thread.currentThread().getName()+" == "+i--);
}
else {
break;
}
}
}
}
}
为什么这里把this换成i 就不行能 |
|