@Override public void run(){
  if (!running.compareAndSet(false,true)) {
    throw new IllegalStateException("Thread is already running");
  }
  sequenceBarrier.clearAlert();
  notifyStart();
  T event=null;
  long nextSequence=sequence.get() + 1L;
  try {
    while (true) {
      try {
        final long availableSequence=sequenceBarrier.waitFor(nextSequence);
        while (nextSequence <= availableSequence) {
          event=dataProvider.get(nextSequence);
          eventHandler.onEvent(event,nextSequence,nextSequence == availableSequence);
          nextSequence++;
        }
        sequence.set(availableSequence);
      }
 catch (      final TimeoutException e) {
        notifyTimeout(sequence.get());
      }
catch (      final AlertException ex) {
        if (!running.get()) {
          break;
        }
      }
catch (      final Throwable ex) {
        exceptionHandler.handleEventException(ex,nextSequence,event);
        sequence.set(nextSequence);
        nextSequence++;
      }
    }
  }
  finally {
    notifyShutdown();
    running.set(false);
  }
}

@ Override public void run ( ) { if ( ! running . compareAndSet ( false , true ) ) { throw new IllegalStateException ( "Thread is already running" ) ; } sequenceBarrier . clearAlert ( ) ; notifyStart ( ) ; T event = null ; long nextSequence = sequence . get ( ) + 1L ; try { while ( true ) { try { final long availableSequence = sequenceBarrier . waitFor ( nextSequence ) ; while ( nextSequence <= availableSequence ) { event = dataProvider . get ( nextSequence ) ; eventHandler . onEvent ( event , nextSequence , nextSequence == availableSequence ) ; nextSequence ++ ; } sequence . set ( availableSequence ) ; } catch ( final TimeoutException e ) { notifyTimeout ( sequence . get ( ) ) ; } catch ( final AlertException ex ) { if ( ! running . get ( ) ) { break ; } } catch ( final Throwable ex ) { exceptionHandler . handleEventException ( ex , nextSequence , event ) ; sequence . set ( nextSequence ) ; nextSequence ++ ; } } } finally { notifyShutdown ( ) ; running . set ( false ) ; } }
it is ok to have another thread rerun this method after a halt ( ) .
