dispatcher是reactor的核心,顾名思义,就是一个分发器,用作事件的分发,当一个事件到达,(即Reacot.notify被调用)最终会由dispatcher进行任务分发调度(dispatcher.dipatch)
Dispatcher根据线程和队列分为下面几种dispatcher,系统现在默认为SynchronousDispatcher(不知道以后会不会变,之前默认的是BlockingQueueDispatcher)
SynchronousDispatcher
当一个事件到达时,直接由reactor所在的线程直接执行
BlockingQueueDispatcher(eventloop)
事件到达时先存储在一个Blockingqueue中,再由统一的后台线程一一顺序执行
ThreadPoolExecutorDispatcher(threadpool)
事件达到时将事件交由线程池统一调度。该线程池为固定大小线程池,(Executors.newFixedThreadPool)线程大小由配置文件指定。
RingBufferDispatcher(ringbuffer)
该dispatcher是吞吐量最高,使用了名头比较响的lmax的Disruptor构建的ringBuffer作为事件存储数组,其实就是一个不断递增,并可覆盖之前循环。
Dispatcher根据线程和队列分为下面几种dispatcher,系统现在默认为SynchronousDispatcher(不知道以后会不会变,之前默认的是BlockingQueueDispatcher)
SynchronousDispatcher
当一个事件到达时,直接由reactor所在的线程直接执行
BlockingQueueDispatcher(eventloop)
事件到达时先存储在一个Blockingqueue中,再由统一的后台线程一一顺序执行
ThreadPoolExecutorDispatcher(threadpool)
事件达到时将事件交由线程池统一调度。该线程池为固定大小线程池,(Executors.newFixedThreadPool)线程大小由配置文件指定。
RingBufferDispatcher(ringbuffer)
该dispatcher是吞吐量最高,使用了名头比较响的lmax的Disruptor构建的ringBuffer作为事件存储数组,其实就是一个不断递增,并可覆盖之前循环。