你把两个循环分成两个线成来写就可以了。样例如下:public class MainTest { Thread ta,tb; class A implements Runnable { public void run() { while(true) { if (Thread.currentThread()==ta) { System.out.println("A"); } } } } class B implements Runnable { public void run() { while(true) { if (Thread.currentThread()==tb) { System.out.println("B"); } } } } public MainTest() { } public static void main(String[] args) { MainTest t = new MainTest(); t.ta = new Thread(t.new A(),"A"); t.tb = new Thread(t.new B(),"B"); t.ta.start(); t.tb.start();} }
那么 程序就会一直在 while(true) 里面 循环
根本不会再理会 Thread.currentThread()==gameThread 了
{
Thread ta,tb;
class A implements Runnable
{
public void run()
{
while(true)
{
if (Thread.currentThread()==ta)
{
System.out.println("A"); }
}
}
}
class B implements Runnable
{
public void run()
{
while(true)
{
if (Thread.currentThread()==tb)
{
System.out.println("B"); }
}
}
} public MainTest()
{
}
public static void main(String[] args) {
MainTest t = new MainTest();
t.ta = new Thread(t.new A(),"A");
t.tb = new Thread(t.new B(),"B");
t.ta.start();
t.tb.start();}
}