@Override public void run(){
  if (!running.compareAndSet(false,true)) {
    throw new IllegalStateException("Thread is already running");
  }
  sequenceBarrier.clearAlert();
  notifyStart();
  boolean processedSequence=true;
  long cachedAvailableSequence=Long.MIN_VALUE;
  long nextSequence=sequence.get();
  T event=null;
  while (true) {
    try {
      if (processedSequence) {
        processedSequence=false;
        do {
          nextSequence=workSequence.get() + 1L;
          sequence.set(nextSequence - 1L);
        }
 while (!workSequence.compareAndSet(nextSequence - 1L,nextSequence));
      }
      if (cachedAvailableSequence >= nextSequence) {
        event=ringBuffer.get(nextSequence);
        workHandler.onEvent(event);
        processedSequence=true;
      }
 else {
        cachedAvailableSequence=sequenceBarrier.waitFor(nextSequence);
      }
    }
 catch (    final AlertException ex) {
      if (!running.get()) {
        break;
      }
    }
catch (    final Throwable ex) {
      exceptionHandler.handleEventException(ex,nextSequence,event);
      processedSequence=true;
    }
  }
  notifyShutdown();
  running.set(false);
}

@ Override public void run ( ) { if ( ! running . compareAndSet ( false , true ) ) { throw new IllegalStateException ( "Thread is already running" ) ; } sequenceBarrier . clearAlert ( ) ; notifyStart ( ) ; boolean processedSequence = true ; long cachedAvailableSequence = Long . MIN_VALUE ; long nextSequence = sequence . get ( ) ; T event = null ; while ( true ) { try { if ( processedSequence ) { processedSequence = false ; do { nextSequence = workSequence . get ( ) + 1L ; sequence . set ( nextSequence - 1L ) ; } while ( ! workSequence . compareAndSet ( nextSequence - 1L , nextSequence ) ) ; } if ( cachedAvailableSequence >= nextSequence ) { event = ringBuffer . get ( nextSequence ) ; workHandler . onEvent ( event ) ; processedSequence = true ; } else { cachedAvailableSequence = sequenceBarrier . waitFor ( nextSequence ) ; } } catch ( final AlertException ex ) { if ( ! running . get ( ) ) { break ; } } catch ( final Throwable ex ) { exceptionHandler . handleEventException ( ex , nextSequence , event ) ; processedSequence = true ; } } notifyShutdown ( ) ; running . set ( false ) ; }
it is ok to have another thread re - run this method after a halt ( ) .
