private void initDispatcherThreads ( Feature . AsynchronousMessageDispatch configuration ) { for ( int i = 0 ; i < configuration . getNumberOfMessageDispatchers ( ) ; i ++ ) { // each thread will run forever and process incoming // message publication requests Thread dispatcher = configuration . getDispatcherThreadFactory ( ) . newThread ( new Runnable ( ) { public void run ( ) { while ( true ) { IMessagePublication publication = null ; try { publication = pendingMessages . take ( ) ; publication . execute ( ) ; } catch ( InterruptedException e ) { Thread . currentThread ( ) . interrupt ( ) ; return ; } catch ( Throwable t ) { handlePublicationError ( new InternalPublicationError ( t , "Error in asynchronous dispatch" , publication ) ) ; } } } } ) ; dispatcher . setName ( "MsgDispatcher-" + i ) ; dispatchers . add ( dispatcher ) ; dispatcher . start ( ) ; } }
initialize the dispatch workers