这里是程序,那位dx帮我看看。public class Game {
public static void main(String args[]){
PingPong table = new PingPong();
Thread alice = new Thread(new Player("bob", table));
Thread bob = new Thread(new Player("alice", table));
Thread t = new Thread();
alice.setName("alice");
bob.setName("bob");
alice.start();
bob.start();try{
//Wait 5seconds
t = Thread.currentThread();
t.yield();
Thread.currentThread().sleep(5000);}
catch(InterruptedException e) {}table.hit("DONE");
try {
Thread.currentThread().sleep(100);}
catch(InterruptedException e) {
}
}}

解决方案 »

  1.   

    Thread.sleep(5000)一般用在单个线程,也就是当前线程。
    而你这个程序有两个线程,一定要用xxx.currentThread()进行判断,当前是那个线程运行。
      

  2.   

    但用Thread.currentThread().sleep(5000)编译不通过!WarningThe static method sleep(long) from the type Thread should be accessed in a static wayGame.javaMyJavaTest/MyLearnline 28
      

  3.   

    Thread.currentThread()可以获得主线程的一个引用.
      

  4.   

    public class Game {
    public void run()
    {
      if(Thead.currentThread()==alice)
      {
          alice.sleep(5000);
     }
     else if(Thead.currentThread()==bob)
    {
    ..
    ..}
    public static void main(String args[]){
    PingPong table = new PingPong();
    Thread alice = new Thread(new Player("bob", table));
    Thread bob = new Thread(new Player("alice", table));
    Thread t = new Thread();
    alice.setName("alice");
    bob.setName("bob");
    alice.start();
    bob.start();
    }试下看好用么
      

  5.   

    sleep()是类方法,不能被对象实例调用。Thread.currentThread()返回的是对象实例,所以不能调用。Thread.sleep()就是让当前线程(执行该语句的线程)睡眠,能符合你的要求了,不用再画蛇添足。
      

  6.   

    我觉得楼上说的很有道理了,根本就不必要用实例来引用sleep,毕竟是共享CPU,
    哪个sleep,跟Thread.sleep()效果都一样的
      

  7.   

    sleep()是个静态方法 无所微效果一样