public void run(){
  while (!interrupted) {
    boolean EOM=false;
    boolean wasRunning=running;
    isPumping=!interrupted && running;
    while (!EOM && !interrupted && running) {
      EOM=dataPump.pump();
      try {
        Thread.sleep(1);
      }
 catch (      InterruptedException ie) {
      }
    }
    if (Printer.debug) {
      Printer.debug("Exited main pump loop because: ");
      if (EOM)       Printer.debug(" -> EOM is reached");
      if (!running)       Printer.debug(" -> running was set to false");
      if (interrupted)       Printer.debug(" -> interrupted was set to true");
    }
    playThreadImplStop();
    if (wasRunning) {
      dataPump.notesOff(true);
    }
    if (EOM) {
      dataPump.setTickPos(sequence.getTickLength());
      MetaMessage message=new MetaMessage();
      try {
        message.setMessage(MidiUtils.META_END_OF_TRACK_TYPE,new byte[0],0);
      }
 catch (      InvalidMidiDataException e1) {
      }
      sendMetaEvents(message);
    }
synchronized (lock) {
      isPumping=false;
      lock.notifyAll();
      while (!running && !interrupted) {
        try {
          lock.wait();
        }
 catch (        Exception ex) {
        }
      }
    }
  }
  if (Printer.debug)   Printer.debug("end of play thread");
}

public void run ( ) { while ( ! interrupted ) { boolean EOM = false ; boolean wasRunning = running ; isPumping = ! interrupted && running ; while ( ! EOM && ! interrupted && running ) { EOM = dataPump . pump ( ) ; try { Thread . sleep ( 1 ) ; } catch ( InterruptedException ie ) { } } if ( Printer . debug ) { Printer . debug ( "Exited main pump loop because: " ) ; if ( EOM ) Printer . debug ( " -> EOM is reached" ) ; if ( ! running ) Printer . debug ( " -> running was set to false" ) ; if ( interrupted ) Printer . debug ( " -> interrupted was set to true" ) ; } playThreadImplStop ( ) ; if ( wasRunning ) { dataPump . notesOff ( true ) ; } if ( EOM ) { dataPump . setTickPos ( sequence . getTickLength ( ) ) ; MetaMessage message = new MetaMessage ( ) ; try { message . setMessage ( MidiUtils . META_END_OF_TRACK_TYPE , new byte [ 0 ] , 0 ) ; } catch ( InvalidMidiDataException e1 ) { } sendMetaEvents ( message ) ; } synchronized ( lock ) { isPumping = false ; lock . notifyAll ( ) ; while ( ! running && ! interrupted ) { try { lock . wait ( ) ; } catch ( Exception ex ) { } } } } if ( Printer . debug ) Printer . debug ( "end of play thread" ) ; }
main process loop driving the media flow . make sure to not synchronize on realtimesequencer anywhere here ( even implicit ) . that is a sure deadlock !
