//下面代码是没办法执行完的,太诡异了,但是更诡异的事是a、b都volatile,更诡异的是线程2打印一下就能正常
public class t1 {
static long a=0;
static long b=0;
static long time;
public static void main(String[] s) {
time=System.currentTimeMillis();
new t1.th1().start();
new t1.th2().start();
System.out.println("start ..");
}
static class th1 extends Thread{
public void run() {
System.out.println("start a");
while(a<100*100) {
if(a==b)a++;
System.out.println(a+" "+b);
}
System.out.println(System.currentTimeMillis()-time);
System.out.println("a is end");
}
}
static class th2 extends Thread{
public void run() {
System.out.println("start b");
while(a<100*100)
{
if(a>b)b++;
// System.out.println(a+" "+b); 执行这条语句的话,能正常
}
System.out.println("b is end ");
}
}
}
--
FROM 171.116.43.*