51,410
社区成员
发帖
与我相关
我的任务
分享public class X implements Runnable
{
private int x,y;
public static void main(String[] args){
X that = new X();
(new Thread(that)).start();
(new Thread(that)).start();
}
public void run(){
for(;;)
{
x++;
y++;
System.out.println("x="+x+",y="+y);
}
}
}
public class X implements Runnable {
private int x, y;
public static void main(String[] args) {
X that = new X();
(new Thread(that)).start();
(new Thread(that)).start();
}
public void run() {
for (;;) {
x++;
y++;
if(x != y){
System.out.println("x:" + x + ":y" + y);
break;
}
}
}
}这样运行一下更神奇