rt.....
想在一个线程里调用另外一个类里的一个方法怎么调用啊?
最好是直接调用方法。

解决方案 »

  1.   

    class  Thread1 extend Thread{
        private YourObject o;
         public Thread1(YourObject o){
          this.o=o;
         }
        public void run(){
         o.method(); 
       }
    }class YourObject {
      public void method(){
      System.out.println("my name is YourObject!");
      }
    }
    public class Test{
       public static void main(String args[]){
        YourObject o=new YourObject();
        Thread  n=new Thread1(o);
         n.start();
        }
    }
      

  2.   

    最好是:
    public synchronized void method(){
      System.out.println("my name is YourObject!");
      }
      

  3.   

    现在想想,还真可能不同,推荐使用pipedOutputStream