question: private void writeOneEvent ( BufferedWriter writer , Event event ) throws MarshallingExcetion { try { if ( _count . getAndIncrement ( ) > 0 ) { while ( ! _firstWritten . get ( ) ) { try { Thread . sleep ( 1 ) ; } catch ( InterruptedException e ) { _logger . warn ( "Sleep interrupted" ) ; } } writer . write ( "," + _mapper . writeValueAsString ( event ) ) ; } else { writer . write ( _mapper . writeValueAsString ( event ) ) ; _firstWritten . set ( true ) ; } } catch ( JsonGenerationException e ) { throw new MarshallingExcetion ( "JSON Generation Error" , e ) ; } catch ( JsonMappingException e ) { throw new MarshallingExcetion ( "JSON Mapping Error" , e ) ; } catch ( IOException e ) { throw new MarshallingExcetion ( "JSON streaming failed: " + event . getEventId ( ) , e ) ; } }
target:  Stream out one event. Since the streaming format for the first event is slightly different from all the rest of events, this method uses a boolean to block event being streamed until the first event is streamed by a thread.