public synchronized void WritePort(final String Msg)
    {
      final Object lock  = new Object();
      boolean writeSucess = false;      class wt implements Runnable{
        public void run(){
          try
          {
            System.out.println("start write port");
            for (int i = 0; i < Msg.length(); i++){
              os.write(Msg.charAt(i));
            }
            os.flush();
          } catch (IOException e) {
            System.out.println("WritePort exception");
          }
          System.out.println(" write port over");
          lock.notifyAll();
        }
      }      try {
        while (!writeSucess) {
            new Thread(new wt()).start();
            lock.wait(300);
            writeSucess = true;
          }
        }catch (InterruptedException ex) {
          System.out.println("Printer timeout!");
        }
    }如何等里面的内部线程超时退出啊,