当前位置:   article > 正文

149、disruptor精通篇_disruptor异常处理

disruptor异常处理

Disruptor为什么这么快

Disruptor不使用锁,通过内存屏障和原子性的CAS操作替换锁

锁机制:

    悲观锁:读写的时候都严格加锁,高并发下锁竞争问题严重,性能低下。

    乐观锁:读的时候不加锁、写的时候才加锁;性能有所提高,但是会引起读写不一致的问题。

缓存基于数组而不是链表,用位运算替代求模。缓存的长度总是2的N次方,这样可以用位运算i&(length-1) 替代i%length

去伪共享,CPU的缓存一般是以缓存行为最小单位的,对应主存的一块相应大小的单元;当前的缓存行大小一般是64字节,每个缓存行一次只能被一个CPU核访问,如果一个缓存行被多个CPU核访问,就会造成竞争,导致某个核必须等其他核处理完了才能继续处理,影响性能。

去除伪共享就是确保CPU核访问某个缓存行时不会出现争用。

预分配缓存对象,通过更新缓存里对象的属性而不是删除对象来减少垃圾回收。

 

数据在缓存中不是以独立的项来存储的,不是单独的变量或指针。

缓存是由缓存行组成的,通常是64字节,(32位计算机就是32字节)。

它有效地引用主内存中的一块地址。一个Java的long类型是8字节,因此在一个缓存行中可以存8个long类型的变量。

 

 

 

 

免费缓存存在弊端,可能会将完全不相关的数据同时缓存,导致缓存命中失效,拖慢性能。

通过增加补全来确保Ring buffer的序列号不会和其他东西同时存在于一个缓存行中。

 

ringBuffer的内存屏障

RingBuffer是核心,Barrier是连接点。

每一个消费者(EventHandler)可能都在处理不同sequence的数据。

waitFor用来请求下一个要处理的sequence。

 

 

 

下面的例子是10个线程并发地往disruptor里面生产事件:

  1. package com.mimaxueyuan.disruptor.demo1;
  2. import java.util.concurrent.CyclicBarrier;
  3. import java.util.concurrent.ExecutorService;
  4. import java.util.concurrent.Executors;
  5. import java.util.concurrent.ThreadFactory;
  6. import com.lmax.disruptor.BlockingWaitStrategy;
  7. import com.lmax.disruptor.RingBuffer;
  8. import com.lmax.disruptor.dsl.Disruptor;
  9. import com.lmax.disruptor.dsl.ProducerType;
  10. public class LongEventMain3 {
  11. @SuppressWarnings("unchecked")
  12. public static void main(String[] args) throws InterruptedException {
  13. // 初始化线程池-用户执行Consumer
  14. //Executor threadFactory = Executors.newCachedThreadPool();
  15. ThreadFactory threadFactory = Executors.defaultThreadFactory();
  16. // 初始化EventFactory
  17. LongEventFactory factory = new LongEventFactory();
  18. // 初始化RingBuffer的大小,必须是2的指数
  19. int bufferSize = 1024;
  20. // 初始化Disruptor
  21. //默认配置
  22. //Disruptor<LongEvent> disruptor = new Disruptor<LongEvent>(factory, bufferSize, threadFactory);
  23. //多线程配置
  24. //Disruptor<LongEvent> disruptor = new Disruptor<LongEvent>(factory, bufferSize, threadFactory,ProducerType.MULTI,new BlockingWaitStrategy());
  25. //单线程配置
  26. Disruptor<LongEvent> disruptor = new Disruptor<LongEvent>(factory, bufferSize, threadFactory,ProducerType.SINGLE,new BlockingWaitStrategy());
  27. // 指定事件处理器
  28. disruptor.handleEventsWith(new LongEventHandler());
  29. // 开启Disruptor,开启所有线程
  30. disruptor.start();
  31. // 获取RingBuffer
  32. RingBuffer<LongEvent> ringBuffer = disruptor.getRingBuffer();
  33. //采用固定模式向RingBuffer中添加事件
  34. final LongEventProducer producer = new LongEventProducer(ringBuffer);
  35. //10线程并发下的Disruptor
  36. final CyclicBarrier cb = new CyclicBarrier(10);
  37. ExecutorService executor1 = Executors.newCachedThreadPool();
  38. for (long i = 0; i<10; i++) {
  39. final long vv = i;
  40. executor1.submit(new Runnable() {
  41. @Override
  42. public void run() {
  43. try {
  44. System.out.println(vv+"is ready..");
  45. cb.await();
  46. producer.onData(vv);
  47. }catch(Exception e) {
  48. e.printStackTrace();
  49. }
  50. }
  51. });
  52. }
  53. //disruptor.shutdown();
  54. }
  55. }

下面是运行的结果:

  1. 0is ready..
  2. 1is ready..
  3. 2is ready..
  4. 3is ready..
  5. 4is ready..
  6. 5is ready..
  7. 6is ready..
  8. 8is ready..
  9. 7is ready..
  10. 9is ready..
  11. [pool-2-thread-4] LongEventProducer product -> LongEvent [value=3]
  12. [pool-2-thread-9] LongEventProducer product -> LongEvent [value=8]
  13. [pool-2-thread-2] LongEventProducer product -> LongEvent [value=1]
  14. [pool-2-thread-8] LongEventProducer product -> LongEvent [value=3]
  15. [pool-2-thread-5] LongEventProducer product -> LongEvent [value=4]
  16. [pool-2-thread-3] LongEventProducer product -> LongEvent [value=2]
  17. [pool-1-thread-1]LongEventHandler consum -> LongEvent [value=3]
  18. [pool-1-thread-1]LongEventHandler consum -> LongEvent [value=8]
  19. [pool-2-thread-6] LongEventProducer product -> LongEvent [value=5]
  20. [pool-2-thread-1] LongEventProducer product -> LongEvent [value=0]
  21. [pool-2-thread-7] LongEventProducer product -> LongEvent [value=6]
  22. [pool-2-thread-10] LongEventProducer product -> LongEvent [value=9]
  23. [pool-1-thread-1]LongEventHandler consum -> LongEvent [value=1]
  24. [pool-1-thread-1]LongEventHandler consum -> LongEvent [value=2]
  25. [pool-1-thread-1]LongEventHandler consum -> LongEvent [value=4]
  26. [pool-1-thread-1]LongEventHandler consum -> LongEvent [value=6]
  27. [pool-1-thread-1]LongEventHandler consum -> LongEvent [value=5]
  28. [pool-1-thread-1]LongEventHandler consum -> LongEvent [value=0]
  29. [pool-1-thread-1]LongEventHandler consum -> LongEvent [value=9]
  30. Process finished with exit code -1

从上面可以看出,在10个事件都成功地制造出来事件之后,10个线程的生产者会同时往disruptor里面扔入事件。

然后disruptor会单线程地去处理事件。

 

 

下面讲disruptor在多线程并行消费的时候,就是有两个消费者(两个handler)的时候,如何自定义处理每个handler中的异常事件。

下面这个代码产生了两个handler。并且自定义了两个EventExceptionHandler处理类去自定义处理每个handler中的异常。

 

  1. package com.mimaxueyuan.disruptor.demo3;
  2. import java.util.concurrent.ExecutorService;
  3. import java.util.concurrent.Executors;
  4. import java.util.concurrent.ThreadFactory;
  5. import com.lmax.disruptor.RingBuffer;
  6. import com.lmax.disruptor.dsl.Disruptor;
  7. public class UserEventMain1 {
  8. public static long startTime;
  9. @SuppressWarnings("unchecked")
  10. public static void main(String[] args) throws InterruptedException {
  11. ThreadFactory threadFactory = Executors.defaultThreadFactory();
  12. UserEventFactory factory = new UserEventFactory();
  13. int bufferSize = 1024;
  14. Disruptor<UserEvent> disruptor = new Disruptor<UserEvent>(factory, bufferSize, threadFactory);
  15. UserEventHandler1 userEventHandler1 = new UserEventHandler1();
  16. UserEventHandler2 userEventHandler2 = new UserEventHandler2();
  17. //指定两个消费者(并行)
  18. disruptor.handleEventsWith(userEventHandler1);
  19. disruptor.handleEventsWith(userEventHandler2);
  20. //设置默认的ExceptionHandler
  21. disruptor.setDefaultExceptionHandler(new DefaultUserEventExceptionHandler());
  22. //为userEventHandler1指定异常处理类为UserEventExceptionHandler1
  23. disruptor.handleExceptionsFor(userEventHandler1).with(new UserEventExceptionHandler1());
  24. //为userEventHandler2指定异常处理类为UserEventExceptionHandler2
  25. disruptor.handleExceptionsFor(userEventHandler2).with(new UserEventExceptionHandler2());
  26. disruptor.start();
  27. RingBuffer<UserEvent> ringBuffer = disruptor.getRingBuffer();
  28. final UserEventProducerWithTranslator translator = new UserEventProducerWithTranslator(ringBuffer);
  29. //5线程并发下的Disruptor
  30. ExecutorService executor1 = Executors.newCachedThreadPool();
  31. startTime = System.currentTimeMillis();
  32. for (int i = 0; i<5; i++) {
  33. final int id = i;
  34. executor1.submit(new Runnable() {
  35. @Override
  36. public void run() {
  37. try {
  38. User user = new User();
  39. user.setId(id);
  40. user.setName("kevin"+id);
  41. user.setAge(id+10);
  42. user.setAddress("beijing"+id);
  43. translator.onData(user);
  44. }catch(Exception e) {
  45. e.printStackTrace();
  46. }
  47. }
  48. });
  49. }
  50. }
  51. }

 

ringbuffer中事件UserEvent类

  1. package com.mimaxueyuan.disruptor.demo3;
  2. public class UserEvent {
  3. private int id;
  4. private String name;
  5. private int age;
  6. private String address;
  7. public int getId() {
  8. return id;
  9. }
  10. public void setId(int id) {
  11. this.id = id;
  12. }
  13. public String getName() {
  14. return name;
  15. }
  16. public void setName(String name) {
  17. this.name = name;
  18. }
  19. public int getAge() {
  20. return age;
  21. }
  22. public void setAge(int age) {
  23. this.age = age;
  24. }
  25. public String getAddress() {
  26. return address;
  27. }
  28. public void setAddress(String address) {
  29. this.address = address;
  30. }
  31. @Override
  32. public String toString() {
  33. return "UserEvent [id=" + id + ", name=" + name + ", age=" + age + ", address=" + address + "]";
  34. }
  35. }

下面是其中自定义的一个异常处理类:

  1. package com.mimaxueyuan.disruptor.demo3;
  2. import com.lmax.disruptor.ExceptionHandler;
  3. public class UserEventExceptionHandler1 implements ExceptionHandler<UserEvent> {
  4. @Override
  5. public void handleEventException(Throwable ex, long sequence, UserEvent event) {
  6. System.out.println("UserEventExceptionHandler1.handleEventException->"+event+"->"+ex.getMessage());
  7. }
  8. @Override
  9. public void handleOnStartException(Throwable ex) {
  10. System.out.println("UserEventExceptionHandler1.handleOnStartException->"+ex.getMessage());
  11. }
  12. @Override
  13. public void handleOnShutdownException(Throwable ex) {
  14. System.out.println("UserEventExceptionHandler1.handleOnShutdownException->"+ex.getMessage());
  15. }
  16. }

 

下面是以自定义格式 往disruptor中放入数据的转换工具类:

  1. package com.mimaxueyuan.disruptor.demo3;
  2. import com.lmax.disruptor.EventTranslatorOneArg;
  3. import com.lmax.disruptor.RingBuffer;
  4. public class UserEventProducerWithTranslator {
  5. private final RingBuffer<UserEvent> ringBuffer;
  6. public UserEventProducerWithTranslator(RingBuffer<UserEvent> ringBuffer) {
  7. this.ringBuffer = ringBuffer;
  8. }
  9. /**
  10. * 一个参数的EventTranslator
  11. */
  12. private static final EventTranslatorOneArg<UserEvent, User> TRANSLATOR_ONE = new EventTranslatorOneArg<UserEvent, User>() {
  13. @Override
  14. public void translateTo(UserEvent event, long sequence, User arg0) {
  15. event.setId(arg0.getId());
  16. event.setAddress(arg0.getAddress());
  17. event.setAge(arg0.getAge());
  18. event.setName(arg0.getName());
  19. }
  20. };
  21. public void onData(User user) {
  22. ringBuffer.publishEvent(TRANSLATOR_ONE, user);
  23. }
  24. }

 

下面是运行的结果,从运行的结果中可以看出,出现异常,并没有阻碍我们继续消费任务。:

  1. 1开始1609075543066[pool-1-thread-1]UserEventHandler1 consum -> UserEvent [id=1, name=kevin1, age=11, address=beijing1],耗时 -> 16,sleep=1s
  2. 2开始1609075543066[pool-1-thread-2]UserEventHandler2 consum -> UserEvent [id=1, name=kevin1, age=11, address=beijing1],耗时 -> 16,sleep=2
  3. 1结束1609075544081[pool-1-thread-1]UserEventHandler1 consum -> UserEvent [id=1, name=kevin1, age=11, address=beijing1Handler1Handler2],耗时 -> 1031,sleep=1s
  4. 1开始1609075544081[pool-1-thread-1]UserEventHandler1 consum -> UserEvent [id=4, name=kevin4, age=14, address=beijing4],耗时 -> 1031,sleep=1s
  5. 2结束1609075545081[pool-1-thread-2]UserEventHandler2 consum -> UserEvent [id=1, name=kevin1, age=11, address=beijing1Handler1Handler2],耗时 -> 2031,sleep=2
  6. 2开始1609075545081[pool-1-thread-2]UserEventHandler2 consum -> UserEvent [id=4, name=kevin4, age=14, address=beijing4Handler1],耗时 -> 2031,sleep=2
  7. UserEventExceptionHandler2.handleEventException->UserEvent [id=4, name=kevin4, age=14, address=beijing4Handler1]->UserEventHandler2抛出异常.
  8. 2开始1609075545081[pool-1-thread-2]UserEventHandler2 consum -> UserEvent [id=2, name=kevin2, age=12, address=beijing2],耗时 -> 2031,sleep=2
  9. 1结束1609075545097[pool-1-thread-1]UserEventHandler1 consum -> UserEvent [id=4, name=kevin4, age=14, address=beijing4Handler1],耗时 -> 2047,sleep=1s
  10. 1开始1609075545097[pool-1-thread-1]UserEventHandler1 consum -> UserEvent [id=2, name=kevin2, age=12, address=beijing2Handler2],耗时 -> 2047,sleep=1s
  11. 1结束1609075546112[pool-1-thread-1]UserEventHandler1 consum -> UserEvent [id=2, name=kevin2, age=12, address=beijing2Handler2Handler1],耗时 -> 3062,sleep=1s
  12. 1开始1609075546112[pool-1-thread-1]UserEventHandler1 consum -> UserEvent [id=3, name=kevin3, age=13, address=beijing3],耗时 -> 3062,sleep=1s
  13. UserEventExceptionHandler1.handleEventException->UserEvent [id=3, name=kevin3, age=13, address=beijing3]->UserEventHandler1抛出异常.
  14. 1开始1609075546112[pool-1-thread-1]UserEventHandler1 consum -> UserEvent [id=0, name=kevin0, age=10, address=beijing0],耗时 -> 3062,sleep=1s
  15. 2结束1609075547097[pool-1-thread-2]UserEventHandler2 consum -> UserEvent [id=2, name=kevin2, age=12, address=beijing2Handler2Handler1],耗时 -> 4047,sleep=2
  16. 2开始1609075547097[pool-1-thread-2]UserEventHandler2 consum -> UserEvent [id=3, name=kevin3, age=13, address=beijing3],耗时 -> 4047,sleep=2
  17. 1结束1609075547128[pool-1-thread-1]UserEventHandler1 consum -> UserEvent [id=0, name=kevin0, age=10, address=beijing0Handler1],耗时 -> 4078,sleep=1s
  18. 2结束1609075549098[pool-1-thread-2]UserEventHandler2 consum -> UserEvent [id=3, name=kevin3, age=13, address=beijing3Handler2],耗时 -> 6048,sleep=2
  19. 2开始1609075549098[pool-1-thread-2]UserEventHandler2 consum -> UserEvent [id=0, name=kevin0, age=10, address=beijing0Handler1],耗时 -> 6048,sleep=2
  20. 2结束1609075551114[pool-1-thread-2]UserEventHandler2 consum -> UserEvent [id=0, name=kevin0, age=10, address=beijing0Handler1Handler2],耗时 -> 8064,sleep=2

 

 

下面讲解disruptor的并行与串行的不同模式:

  1. /**
  2. * h1
  3. * h2
  4. */
  5. //指定两个消费者(并行)
  6. disruptor.handleEventsWith(userEventHandler1);
  7. disruptor.handleEventsWith(userEventHandler2);

上面这段代码表示两个消费者是并行的情况,

下面是运行的结果:

由运行的结果可以看出,线程2和线程1的开始时间和结束时间,都存在同时开始,同时结束的情况,可见两个线程是并行的。

  1. 2开始1609076143907[pool-1-thread-2]UserEventHandler2 consum -> UserEvent [id=1, name=kevin1, age=11, address=beijing1],耗时 -> 1609076143907,sleep=2
  2. 1开始1609076143907[pool-1-thread-1]UserEventHandler1 consum -> UserEvent [id=1, name=kevin1, age=11, address=beijing1],耗时 -> 1609076143907,sleep=1s
  3. 1结束1609076144907[pool-1-thread-1]UserEventHandler1 consum -> UserEvent [id=1, name=kevin1, age=11, address=beijing1Handler2Handler1],耗时 -> 1609076144907,sleep=1s
  4. 1开始1609076144907[pool-1-thread-1]UserEventHandler1 consum -> UserEvent [id=2, name=kevin2, age=12, address=beijing2],耗时 -> 1609076144907,sleep=1s
  5. 2结束1609076145907[pool-1-thread-2]UserEventHandler2 consum -> UserEvent [id=1, name=kevin1, age=11, address=beijing1Handler2Handler1],耗时 -> 1609076145907,sleep=2
  6. 2开始1609076145907[pool-1-thread-2]UserEventHandler2 consum -> UserEvent [id=2, name=kevin2, age=12, address=beijing2Handler1],耗时 -> 1609076145907,sleep=2
  7. 1结束1609076145923[pool-1-thread-1]UserEventHandler1 consum -> UserEvent [id=2, name=kevin2, age=12, address=beijing2Handler1Handler2],耗时 -> 1609076145923,sleep=1s
  8. 1开始1609076145923[pool-1-thread-1]UserEventHandler1 consum -> UserEvent [id=3, name=kevin3, age=13, address=beijing3],耗时 -> 1609076145923,sleep=1s
  9. DefaultUserEventExceptionHandler.handleEventException->UserEvent [id=3, name=kevin3, age=13, address=beijing3]->UserEventHandler1抛出异常.
  10. 1开始1609076145923[pool-1-thread-1]UserEventHandler1 consum -> UserEvent [id=4, name=kevin4, age=14, address=beijing4],耗时 -> 1609076145923,sleep=1s
  11. 1结束1609076146923[pool-1-thread-1]UserEventHandler1 consum -> UserEvent [id=4, name=kevin4, age=14, address=beijing4Handler1],耗时 -> 1609076146923,sleep=1s
  12. 1开始1609076146923[pool-1-thread-1]UserEventHandler1 consum -> UserEvent [id=0, name=kevin0, age=10, address=beijing0],耗时 -> 1609076146923,sleep=1s
  13. 2结束1609076147907[pool-1-thread-2]UserEventHandler2 consum -> UserEvent [id=2, name=kevin2, age=12, address=beijing2Handler1Handler2],耗时 -> 1609076147907,sleep=2
  14. 2开始1609076147907[pool-1-thread-2]UserEventHandler2 consum -> UserEvent [id=3, name=kevin3, age=13, address=beijing3],耗时 -> 1609076147907,sleep=2
  15. 1结束1609076147923[pool-1-thread-1]UserEventHandler1 consum -> UserEvent [id=0, name=kevin0, age=10, address=beijing0Handler1],耗时 -> 1609076147923,sleep=1s
  16. 2结束1609076149923[pool-1-thread-2]UserEventHandler2 consum -> UserEvent [id=3, name=kevin3, age=13, address=beijing3Handler2],耗时 -> 1609076149923,sleep=2
  17. 2开始1609076149923[pool-1-thread-2]UserEventHandler2 consum -> UserEvent [id=4, name=kevin4, age=14, address=beijing4Handler1],耗时 -> 1609076149923,sleep=2
  18. DefaultUserEventExceptionHandler.handleEventException->UserEvent [id=4, name=kevin4, age=14, address=beijing4Handler1]->UserEventHandler2抛出异常.
  19. 2开始1609076149923[pool-1-thread-2]UserEventHandler2 consum -> UserEvent [id=0, name=kevin0, age=10, address=beijing0Handler1],耗时 -> 1609076149923,sleep=2
  20. 2结束1609076151939[pool-1-thread-2]UserEventHandler2 consum -> UserEvent [id=0, name=kevin0, age=10, address=beijing0Handler1Handler2],耗时 -> 1609076151939,sleep=2

 

 

 

下面的代码是指定两个消费者串行:

  1. /**
  2. * h1-h2
  3. */
  4. //指定两个消费者(串行)
  5. disruptor.handleEventsWith(userEventHandler1).handleEventsWith(userEventHandler2);

下面是运行的结果,从结果中看,线程是先执行的线程1,再执行的线程2。两个线程是串行执行的:

  1. 1开始1609077284208[pool-1-thread-1]UserEventHandler1 consum -> UserEvent [id=1, name=kevin1, age=11, address=beijing1],耗时 -> 1609077284208,sleep=1s
  2. 1结束1609077285208[pool-1-thread-1]UserEventHandler1 consum -> UserEvent [id=1, name=kevin1, age=11, address=beijing1Handler1],耗时 -> 1609077285208,sleep=1s
  3. 1开始1609077285208[pool-1-thread-1]UserEventHandler1 consum -> UserEvent [id=2, name=kevin2, age=12, address=beijing2],耗时 -> 1609077285208,sleep=1s
  4. 1结束1609077286224[pool-1-thread-1]UserEventHandler1 consum -> UserEvent [id=2, name=kevin2, age=12, address=beijing2Handler1],耗时 -> 1609077286224,sleep=1s
  5. 1开始1609077286224[pool-1-thread-1]UserEventHandler1 consum -> UserEvent [id=3, name=kevin3, age=13, address=beijing3],耗时 -> 1609077286224,sleep=1s
  6. 1结束1609077287239[pool-1-thread-1]UserEventHandler1 consum -> UserEvent [id=3, name=kevin3, age=13, address=beijing3Handler1],耗时 -> 1609077287239,sleep=1s
  7. 1开始1609077287239[pool-1-thread-1]UserEventHandler1 consum -> UserEvent [id=4, name=kevin4, age=14, address=beijing4],耗时 -> 1609077287239,sleep=1s
  8. 1结束1609077288239[pool-1-thread-1]UserEventHandler1 consum -> UserEvent [id=4, name=kevin4, age=14, address=beijing4Handler1],耗时 -> 1609077288239,sleep=1s
  9. 1开始1609077288239[pool-1-thread-1]UserEventHandler1 consum -> UserEvent [id=0, name=kevin0, age=10, address=beijing0],耗时 -> 1609077288239,sleep=1s
  10. 2开始1609077288239[pool-1-thread-2]UserEventHandler2 consum -> UserEvent [id=1, name=kevin1, age=11, address=beijing1Handler1],耗时 -> 1609077288239,sleep=2
  11. 1结束1609077289239[pool-1-thread-1]UserEventHandler1 consum -> UserEvent [id=0, name=kevin0, age=10, address=beijing0Handler1],耗时 -> 1609077289239,sleep=1s
  12. 2结束1609077290239[pool-1-thread-2]UserEventHandler2 consum -> UserEvent [id=1, name=kevin1, age=11, address=beijing1Handler1Handler2],耗时 -> 1609077290239,sleep=2
  13. 2开始1609077290239[pool-1-thread-2]UserEventHandler2 consum -> UserEvent [id=2, name=kevin2, age=12, address=beijing2Handler1],耗时 -> 1609077290239,sleep=2
  14. 2结束1609077292239[pool-1-thread-2]UserEventHandler2 consum -> UserEvent [id=2, name=kevin2, age=12, address=beijing2Handler1Handler2],耗时 -> 1609077292239,sleep=2
  15. 2开始1609077292239[pool-1-thread-2]UserEventHandler2 consum -> UserEvent [id=3, name=kevin3, age=13, address=beijing3Handler1],耗时 -> 1609077292239,sleep=2
  16. 2结束1609077294239[pool-1-thread-2]UserEventHandler2 consum -> UserEvent [id=3, name=kevin3, age=13, address=beijing3Handler1Handler2],耗时 -> 1609077294239,sleep=2
  17. 2开始1609077294239[pool-1-thread-2]UserEventHandler2 consum -> UserEvent [id=4, name=kevin4, age=14, address=beijing4Handler1],耗时 -> 1609077294239,sleep=2
  18. 2结束1609077296255[pool-1-thread-2]UserEventHandler2 consum -> UserEvent [id=4, name=kevin4, age=14, address=beijing4Handler1Handler2],耗时 -> 1609077296255,sleep=2
  19. 2开始1609077296255[pool-1-thread-2]UserEventHandler2 consum -> UserEvent [id=0, name=kevin0, age=10, address=beijing0Handler1],耗时 -> 1609077296255,sleep=2
  20. 2结束1609077298271[pool-1-thread-2]UserEventHandler2 consum -> UserEvent [id=0, name=kevin0, age=10, address=beijing0Handler1Handler2],耗时 -> 1609077298271,sleep=2
  21. Process finished with exit code -1

 

 

下面是四个消费者,其中的两个先并行,后面两个在前面两个消费者执行完毕的时候,再串行执行任务:

  1. /**
  2. * h1
  3. * -h3-h4
  4. * h2
  5. */
  6. //先并行再串行
  7. EventHandlerGroup<UserEvent> group1 = disruptor.handleEventsWith(userEventHandler2);
  8. EventHandlerGroup<UserEvent> group2 = disruptor.handleEventsWith(userEventHandler1);
  9. group1.and(group2).handleEventsWith(userEventHandler3).handleEventsWith(userEventHandler4);

下面是运行的结果:

  1. 2开始1609077487833[pool-1-thread-1]UserEventHandler2 consum -> UserEvent [id=4, name=kevin4, age=14, address=beijing4],耗时 -> 1609077487833,sleep=2
  2. 1开始1609077487833[pool-1-thread-2]UserEventHandler1 consum -> UserEvent [id=4, name=kevin4, age=14, address=beijing4],耗时 -> 1609077487833,sleep=1s
  3. 1结束1609077488833[pool-1-thread-2]UserEventHandler1 consum -> UserEvent [id=4, name=kevin4, age=14, address=beijing4Handler2Handler1],耗时 -> 1609077488833,sleep=1s
  4. 1开始1609077488833[pool-1-thread-2]UserEventHandler1 consum -> UserEvent [id=3, name=kevin3, age=13, address=beijing3],耗时 -> 1609077488833,sleep=1s
  5. 1结束1609077489849[pool-1-thread-2]UserEventHandler1 consum -> UserEvent [id=3, name=kevin3, age=13, address=beijing3Handler1],耗时 -> 1609077489864,sleep=1s
  6. 1开始1609077489864[pool-1-thread-2]UserEventHandler1 consum -> UserEvent [id=2, name=kevin2, age=12, address=beijing2],耗时 -> 1609077489864,sleep=1s
  7. 2结束1609077489864[pool-1-thread-1]UserEventHandler2 consum -> UserEvent [id=4, name=kevin4, age=14, address=beijing4Handler2Handler1],耗时 -> 1609077489864,sleep=2
  8. 2开始1609077489864[pool-1-thread-1]UserEventHandler2 consum -> UserEvent [id=3, name=kevin3, age=13, address=beijing3Handler1],耗时 -> 1609077489864,sleep=2
  9. 1结束1609077490880[pool-1-thread-2]UserEventHandler1 consum -> UserEvent [id=2, name=kevin2, age=12, address=beijing2Handler1],耗时 -> 1609077490880,sleep=1s
  10. 1开始1609077490880[pool-1-thread-2]UserEventHandler1 consum -> UserEvent [id=1, name=kevin1, age=11, address=beijing1],耗时 -> 1609077490880,sleep=1s
  11. 2结束1609077491880[pool-1-thread-1]UserEventHandler2 consum -> UserEvent [id=3, name=kevin3, age=13, address=beijing3Handler1Handler2],耗时 -> 1609077491880,sleep=2
  12. 1结束1609077491880[pool-1-thread-2]UserEventHandler1 consum -> UserEvent [id=1, name=kevin1, age=11, address=beijing1Handler1],耗时 -> 1609077491880,sleep=1s
  13. 1开始1609077491880[pool-1-thread-2]UserEventHandler1 consum -> UserEvent [id=0, name=kevin0, age=10, address=beijing0],耗时 -> 1609077491880,sleep=1s
  14. 2开始1609077491880[pool-1-thread-1]UserEventHandler2 consum -> UserEvent [id=2, name=kevin2, age=12, address=beijing2Handler1],耗时 -> 1609077491880,sleep=2
  15. 1结束1609077492895[pool-1-thread-2]UserEventHandler1 consum -> UserEvent [id=0, name=kevin0, age=10, address=beijing0Handler1],耗时 -> 1609077492895,sleep=1s
  16. 2结束1609077493895[pool-1-thread-1]UserEventHandler2 consum -> UserEvent [id=2, name=kevin2, age=12, address=beijing2Handler1Handler2],耗时 -> 1609077493895,sleep=2
  17. 2开始1609077493895[pool-1-thread-1]UserEventHandler2 consum -> UserEvent [id=1, name=kevin1, age=11, address=beijing1Handler1],耗时 -> 1609077493895,sleep=2
  18. 2结束1609077495911[pool-1-thread-1]UserEventHandler2 consum -> UserEvent [id=1, name=kevin1, age=11, address=beijing1Handler1Handler2],耗时 -> 1609077495911,sleep=2
  19. 2开始1609077495911[pool-1-thread-1]UserEventHandler2 consum -> UserEvent [id=0, name=kevin0, age=10, address=beijing0Handler1],耗时 -> 1609077495911,sleep=2
  20. 3开始1609077495911[pool-1-thread-3]UserEventHandler3 consum -> UserEvent [id=4, name=kevin4, age=14, address=beijing4Handler2Handler1],耗时 -> 1609077495911,sleep=3
  21. 2结束1609077497911[pool-1-thread-1]UserEventHandler2 consum -> UserEvent [id=0, name=kevin0, age=10, address=beijing0Handler1Handler2],耗时 -> 1609077497911,sleep=2
  22. 3结束1609077498911[pool-1-thread-3]UserEventHandler3 consum -> UserEvent [id=4, name=kevin4, age=14, address=beijing4Handler2Handler1Handler3],耗时 -> 1609077498911,sleep=3
  23. 3开始1609077498911[pool-1-thread-3]UserEventHandler3 consum -> UserEvent [id=3, name=kevin3, age=13, address=beijing3Handler1Handler2],耗时 -> 1609077498911,sleep=3
  24. 3结束1609077501927[pool-1-thread-3]UserEventHandler3 consum -> UserEvent [id=3, name=kevin3, age=13, address=beijing3Handler1Handler2Handler3],耗时 -> 1609077501927,sleep=3
  25. 3开始1609077501927[pool-1-thread-3]UserEventHandler3 consum -> UserEvent [id=2, name=kevin2, age=12, address=beijing2Handler1Handler2],耗时 -> 1609077501927,sleep=3
  26. 3结束1609077504927[pool-1-thread-3]UserEventHandler3 consum -> UserEvent [id=2, name=kevin2, age=12, address=beijing2Handler1Handler2Handler3],耗时 -> 1609077504927,sleep=3
  27. 3开始1609077504927[pool-1-thread-3]UserEventHandler3 consum -> UserEvent [id=1, name=kevin1, age=11, address=beijing1Handler1Handler2],耗时 -> 1609077504927,sleep=3
  28. 3结束1609077507942[pool-1-thread-3]UserEventHandler3 consum -> UserEvent [id=1, name=kevin1, age=11, address=beijing1Handler1Handler2Handler3],耗时 -> 1609077507942,sleep=3
  29. 3开始1609077507942[pool-1-thread-3]UserEventHandler3 consum -> UserEvent [id=0, name=kevin0, age=10, address=beijing0Handler1Handler2],耗时 -> 1609077507942,sleep=3
  30. 4开始1609077507942[pool-1-thread-4]UserEventHandler4 consum -> UserEvent [id=4, name=kevin4, age=14, address=beijing4Handler2Handler1Handler3],耗时 -> 1609077507942,sleep=4
  31. 3结束1609077510942[pool-1-thread-3]UserEventHandler3 consum -> UserEvent [id=0, name=kevin0, age=10, address=beijing0Handler1Handler2Handler3],耗时 -> 1609077510942,sleep=3
  32. 4结束1609077511942[pool-1-thread-4]UserEventHandler4 consum -> UserEvent [id=4, name=kevin4, age=14, address=beijing4Handler2Handler1Handler3Handler4],耗时 -> 1609077511942,sleep=4
  33. 4开始1609077511942[pool-1-thread-4]UserEventHandler4 consum -> UserEvent [id=3, name=kevin3, age=13, address=beijing3Handler1Handler2Handler3],耗时 -> 1609077511942,sleep=4
  34. 4结束1609077515942[pool-1-thread-4]UserEventHandler4 consum -> UserEvent [id=3, name=kevin3, age=13, address=beijing3Handler1Handler2Handler3Handler4],耗时 -> 1609077515942,sleep=4
  35. 4开始1609077515942[pool-1-thread-4]UserEventHandler4 consum -> UserEvent [id=2, name=kevin2, age=12, address=beijing2Handler1Handler2Handler3],耗时 -> 1609077515942,sleep=4
  36. 4结束1609077519958[pool-1-thread-4]UserEventHandler4 consum -> UserEvent [id=2, name=kevin2, age=12, address=beijing2Handler1Handler2Handler3Handler4],耗时 -> 1609077519958,sleep=4
  37. 4开始1609077519958[pool-1-thread-4]UserEventHandler4 consum -> UserEvent [id=1, name=kevin1, age=11, address=beijing1Handler1Handler2Handler3],耗时 -> 1609077519958,sleep=4
  38. 4结束1609077523974[pool-1-thread-4]UserEventHandler4 consum -> UserEvent [id=1, name=kevin1, age=11, address=beijing1Handler1Handler2Handler3Handler4],耗时 -> 1609077523974,sleep=4
  39. 4开始1609077523974[pool-1-thread-4]UserEventHandler4 consum -> UserEvent [id=0, name=kevin0, age=10, address=beijing0Handler1Handler2Handler3],耗时 -> 1609077523974,sleep=4
  40. 4结束1609077527974[pool-1-thread-4]UserEventHandler4 consum -> UserEvent [id=0, name=kevin0, age=10, address=beijing0Handler1Handler2Handler3Handler4],耗时 -> 1609077527974,sleep=4
  41. Process finished with exit code -1

 

 

下面是5个任务,1和2串行,3和4串行,并且1和2,3和4整体上是并联的,最后串联一个1

  1. /**
  2. * h1-h2
  3. * -h1
  4. * h3-h4
  5. */
  6. EventHandlerGroup<UserEvent> group1 = disruptor.handleEventsWith(userEventHandler1).handleEventsWith(userEventHandler2);
  7. EventHandlerGroup<UserEvent> group2 = disruptor.handleEventsWith(userEventHandler3).handleEventsWith(userEventHandler4);
  8. group1.and(group2).handleEventsWith(userEventHandler1);

下面是执行的结果:

  1. 1开始1609077674297[pool-1-thread-1]UserEventHandler1 consum -> UserEvent [id=0, name=kevin0, age=10, address=beijing0],耗时 -> 1609077674297,sleep=1s
  2. 3开始1609077674297[pool-1-thread-3]UserEventHandler3 consum -> UserEvent [id=0, name=kevin0, age=10, address=beijing0],耗时 -> 1609077674297,sleep=3
  3. 1结束1609077675312[pool-1-thread-1]UserEventHandler1 consum -> UserEvent [id=0, name=kevin0, age=10, address=beijing0Handler1Handler3],耗时 -> 1609077675312,sleep=1s
  4. 1开始1609077675312[pool-1-thread-1]UserEventHandler1 consum -> UserEvent [id=4, name=kevin4, age=14, address=beijing4],耗时 -> 1609077675312,sleep=1s
  5. 1结束1609077676312[pool-1-thread-1]UserEventHandler1 consum -> UserEvent [id=4, name=kevin4, age=14, address=beijing4Handler1],耗时 -> 1609077676312,sleep=1s
  6. 1开始1609077676312[pool-1-thread-1]UserEventHandler1 consum -> UserEvent [id=3, name=kevin3, age=13, address=beijing3],耗时 -> 1609077676312,sleep=1s
  7. 3结束1609077677328[pool-1-thread-3]UserEventHandler3 consum -> UserEvent [id=0, name=kevin0, age=10, address=beijing0Handler1Handler3],耗时 -> 1609077677328,sleep=3
  8. 3开始1609077677328[pool-1-thread-3]UserEventHandler3 consum -> UserEvent [id=4, name=kevin4, age=14, address=beijing4Handler1],耗时 -> 1609077677328,sleep=3
  9. 1结束1609077677328[pool-1-thread-1]UserEventHandler1 consum -> UserEvent [id=3, name=kevin3, age=13, address=beijing3Handler1],耗时 -> 1609077677328,sleep=1s
  10. 1开始1609077677328[pool-1-thread-1]UserEventHandler1 consum -> UserEvent [id=2, name=kevin2, age=12, address=beijing2],耗时 -> 1609077677328,sleep=1s
  11. 1结束1609077678344[pool-1-thread-1]UserEventHandler1 consum -> UserEvent [id=2, name=kevin2, age=12, address=beijing2Handler1],耗时 -> 1609077678344,sleep=1s
  12. 1开始1609077678344[pool-1-thread-1]UserEventHandler1 consum -> UserEvent [id=1, name=kevin1, age=11, address=beijing1],耗时 -> 1609077678344,sleep=1s
  13. 1结束1609077679344[pool-1-thread-1]UserEventHandler1 consum -> UserEvent [id=1, name=kevin1, age=11, address=beijing1Handler1],耗时 -> 1609077679344,sleep=1s
  14. 2开始1609077679344[pool-1-thread-2]UserEventHandler2 consum -> UserEvent [id=0, name=kevin0, age=10, address=beijing0Handler1Handler3],耗时 -> 1609077679344,sleep=2
  15. 3结束1609077680344[pool-1-thread-3]UserEventHandler3 consum -> UserEvent [id=4, name=kevin4, age=14, address=beijing4Handler1Handler3],耗时 -> 1609077680344,sleep=3
  16. 3开始1609077680344[pool-1-thread-3]UserEventHandler3 consum -> UserEvent [id=3, name=kevin3, age=13, address=beijing3Handler1],耗时 -> 1609077680344,sleep=3
  17. 2结束1609077681359[pool-1-thread-2]UserEventHandler2 consum -> UserEvent [id=0, name=kevin0, age=10, address=beijing0Handler1Handler3Handler2],耗时 -> 1609077681359,sleep=2
  18. 2开始1609077681359[pool-1-thread-2]UserEventHandler2 consum -> UserEvent [id=4, name=kevin4, age=14, address=beijing4Handler1Handler3],耗时 -> 1609077681359,sleep=2
  19. 3结束1609077683350[pool-1-thread-3]UserEventHandler3 consum -> UserEvent [id=3, name=kevin3, age=13, address=beijing3Handler1Handler3],耗时 -> 1609077683350,sleep=3
  20. 3开始1609077683350[pool-1-thread-3]UserEventHandler3 consum -> UserEvent [id=2, name=kevin2, age=12, address=beijing2Handler1],耗时 -> 1609077683350,sleep=3
  21. 2结束1609077683365[pool-1-thread-2]UserEventHandler2 consum -> UserEvent [id=4, name=kevin4, age=14, address=beijing4Handler1Handler3Handler2],耗时 -> 1609077683365,sleep=2
  22. 2开始1609077683365[pool-1-thread-2]UserEventHandler2 consum -> UserEvent [id=3, name=kevin3, age=13, address=beijing3Handler1Handler3],耗时 -> 1609077683365,sleep=2
  23. 2结束1609077685366[pool-1-thread-2]UserEventHandler2 consum -> UserEvent [id=3, name=kevin3, age=13, address=beijing3Handler1Handler3Handler2],耗时 -> 1609077685366,sleep=2
  24. 2开始1609077685366[pool-1-thread-2]UserEventHandler2 consum -> UserEvent [id=2, name=kevin2, age=12, address=beijing2Handler1Handler3],耗时 -> 1609077685366,sleep=2
  25. 3结束1609077686366[pool-1-thread-3]UserEventHandler3 consum -> UserEvent [id=2, name=kevin2, age=12, address=beijing2Handler1Handler3Handler2],耗时 -> 1609077686366,sleep=3
  26. 3开始1609077686366[pool-1-thread-3]UserEventHandler3 consum -> UserEvent [id=1, name=kevin1, age=11, address=beijing1Handler1],耗时 -> 1609077686366,sleep=3
  27. 2结束1609077687381[pool-1-thread-2]UserEventHandler2 consum -> UserEvent [id=2, name=kevin2, age=12, address=beijing2Handler1Handler3Handler2],耗时 -> 1609077687381,sleep=2
  28. 2开始1609077687381[pool-1-thread-2]UserEventHandler2 consum -> UserEvent [id=1, name=kevin1, age=11, address=beijing1Handler1Handler3],耗时 -> 1609077687381,sleep=2
  29. 3结束1609077689366[pool-1-thread-3]UserEventHandler3 consum -> UserEvent [id=1, name=kevin1, age=11, address=beijing1Handler1Handler3Handler2],耗时 -> 1609077689366,sleep=3
  30. 4开始1609077689366[pool-1-thread-4]UserEventHandler4 consum -> UserEvent [id=0, name=kevin0, age=10, address=beijing0Handler1Handler3Handler2],耗时 -> 1609077689366,sleep=4
  31. 2结束1609077689381[pool-1-thread-2]UserEventHandler2 consum -> UserEvent [id=1, name=kevin1, age=11, address=beijing1Handler1Handler3Handler2],耗时 -> 1609077689381,sleep=2
  32. 4结束1609077693366[pool-1-thread-4]UserEventHandler4 consum -> UserEvent [id=0, name=kevin0, age=10, address=beijing0Handler1Handler3Handler2Handler4],耗时 -> 1609077693366,sleep=4
  33. 4开始1609077693366[pool-1-thread-4]UserEventHandler4 consum -> UserEvent [id=4, name=kevin4, age=14, address=beijing4Handler1Handler3Handler2],耗时 -> 1609077693366,sleep=4
  34. 4结束1609077697381[pool-1-thread-4]UserEventHandler4 consum -> UserEvent [id=4, name=kevin4, age=14, address=beijing4Handler1Handler3Handler2Handler4],耗时 -> 1609077697381,sleep=4
  35. 4开始1609077697381[pool-1-thread-4]UserEventHandler4 consum -> UserEvent [id=3, name=kevin3, age=13, address=beijing3Handler1Handler3Handler2],耗时 -> 1609077697381,sleep=4
  36. 4结束1609077701397[pool-1-thread-4]UserEventHandler4 consum -> UserEvent [id=3, name=kevin3, age=13, address=beijing3Handler1Handler3Handler2Handler4],耗时 -> 1609077701397,sleep=4
  37. 4开始1609077701397[pool-1-thread-4]UserEventHandler4 consum -> UserEvent [id=2, name=kevin2, age=12, address=beijing2Handler1Handler3Handler2],耗时 -> 1609077701397,sleep=4
  38. 4结束1609077705397[pool-1-thread-4]UserEventHandler4 consum -> UserEvent [id=2, name=kevin2, age=12, address=beijing2Handler1Handler3Handler2Handler4],耗时 -> 1609077705397,sleep=4
  39. 4开始1609077705397[pool-1-thread-4]UserEventHandler4 consum -> UserEvent [id=1, name=kevin1, age=11, address=beijing1Handler1Handler3Handler2],耗时 -> 1609077705397,sleep=4
  40. 4结束1609077709412[pool-1-thread-4]UserEventHandler4 consum -> UserEvent [id=1, name=kevin1, age=11, address=beijing1Handler1Handler3Handler2Handler4],耗时 -> 1609077709412,sleep=4
  41. 1开始1609077709412[pool-1-thread-5]UserEventHandler1 consum -> UserEvent [id=0, name=kevin0, age=10, address=beijing0Handler1Handler3Handler2Handler4],耗时 -> 1609077709412,sleep=1s
  42. 1结束1609077710412[pool-1-thread-5]UserEventHandler1 consum -> UserEvent [id=0, name=kevin0, age=10, address=beijing0Handler1Handler3Handler2Handler4Handler1],耗时 -> 1609077710412,sleep=1s
  43. 1开始1609077710412[pool-1-thread-5]UserEventHandler1 consum -> UserEvent [id=4, name=kevin4, age=14, address=beijing4Handler1Handler3Handler2Handler4],耗时 -> 1609077710412,sleep=1s
  44. 1结束1609077711428[pool-1-thread-5]UserEventHandler1 consum -> UserEvent [id=4, name=kevin4, age=14, address=beijing4Handler1Handler3Handler2Handler4Handler1],耗时 -> 1609077711428,sleep=1s
  45. 1开始1609077711428[pool-1-thread-5]UserEventHandler1 consum -> UserEvent [id=3, name=kevin3, age=13, address=beijing3Handler1Handler3Handler2Handler4],耗时 -> 1609077711428,sleep=1s
  46. 1结束1609077712444[pool-1-thread-5]UserEventHandler1 consum -> UserEvent [id=3, name=kevin3, age=13, address=beijing3Handler1Handler3Handler2Handler4Handler1],耗时 -> 1609077712444,sleep=1s
  47. 1开始1609077712444[pool-1-thread-5]UserEventHandler1 consum -> UserEvent [id=2, name=kevin2, age=12, address=beijing2Handler1Handler3Handler2Handler4],耗时 -> 1609077712444,sleep=1s
  48. 1结束1609077713444[pool-1-thread-5]UserEventHandler1 consum -> UserEvent [id=2, name=kevin2, age=12, address=beijing2Handler1Handler3Handler2Handler4Handler1],耗时 -> 1609077713444,sleep=1s
  49. 1开始1609077713444[pool-1-thread-5]UserEventHandler1 consum -> UserEvent [id=1, name=kevin1, age=11, address=beijing1Handler1Handler3Handler2Handler4],耗时 -> 1609077713444,sleep=1s
  50. 1结束1609077714459[pool-1-thread-5]UserEventHandler1 consum -> UserEvent [id=1, name=kevin1, age=11, address=beijing1Handler1Handler3Handler2Handler4Handler1],耗时 -> 1609077714459,sleep=1s
  51. Process finished with exit code -1

 

 

 

下面是一种奇怪的串行方式:

  1. /**
  2. * h2
  3. * h4- -h1
  4. * h3
  5. */
  6. disruptor.handleEventsWith(userEventHandler4).handleEventsWith(userEventHandler2,userEventHandler3).handleEventsWith(userEventHandler1);

下面是执行的结果:

  1. 4开始1609077876344[pool-1-thread-1]UserEventHandler4 consum -> UserEvent [id=4, name=kevin4, age=14, address=beijing4],耗时 -> 1609077876344,sleep=4
  2. 4结束1609077880360[pool-1-thread-1]UserEventHandler4 consum -> UserEvent [id=4, name=kevin4, age=14, address=beijing4Handler4],耗时 -> 1609077880360,sleep=4
  3. 4开始1609077880360[pool-1-thread-1]UserEventHandler4 consum -> UserEvent [id=3, name=kevin3, age=13, address=beijing3],耗时 -> 1609077880360,sleep=4
  4. 4结束1609077884360[pool-1-thread-1]UserEventHandler4 consum -> UserEvent [id=3, name=kevin3, age=13, address=beijing3Handler4],耗时 -> 1609077884360,sleep=4
  5. 4开始1609077884360[pool-1-thread-1]UserEventHandler4 consum -> UserEvent [id=0, name=kevin0, age=10, address=beijing0],耗时 -> 1609077884360,sleep=4
  6. 4结束1609077888360[pool-1-thread-1]UserEventHandler4 consum -> UserEvent [id=0, name=kevin0, age=10, address=beijing0Handler4],耗时 -> 1609077888360,sleep=4
  7. 4开始1609077888360[pool-1-thread-1]UserEventHandler4 consum -> UserEvent [id=2, name=kevin2, age=12, address=beijing2],耗时 -> 1609077888360,sleep=4
  8. 4结束1609077892376[pool-1-thread-1]UserEventHandler4 consum -> UserEvent [id=2, name=kevin2, age=12, address=beijing2Handler4],耗时 -> 1609077892376,sleep=4
  9. 4开始1609077892376[pool-1-thread-1]UserEventHandler4 consum -> UserEvent [id=1, name=kevin1, age=11, address=beijing1],耗时 -> 1609077892376,sleep=4
  10. 4结束1609077896391[pool-1-thread-1]UserEventHandler4 consum -> UserEvent [id=1, name=kevin1, age=11, address=beijing1Handler4],耗时 -> 1609077896391,sleep=4
  11. 3开始1609077896391[pool-1-thread-3]UserEventHandler3 consum -> UserEvent [id=4, name=kevin4, age=14, address=beijing4Handler4],耗时 -> 1609077896391,sleep=3
  12. 2开始1609077896391[pool-1-thread-2]UserEventHandler2 consum -> UserEvent [id=4, name=kevin4, age=14, address=beijing4Handler4],耗时 -> 1609077896391,sleep=2
  13. 2结束1609077898391[pool-1-thread-2]UserEventHandler2 consum -> UserEvent [id=4, name=kevin4, age=14, address=beijing4Handler4Handler3Handler2],耗时 -> 1609077898391,sleep=2
  14. 2开始1609077898391[pool-1-thread-2]UserEventHandler2 consum -> UserEvent [id=3, name=kevin3, age=13, address=beijing3Handler4],耗时 -> 1609077898391,sleep=2
  15. 3结束1609077899391[pool-1-thread-3]UserEventHandler3 consum -> UserEvent [id=4, name=kevin4, age=14, address=beijing4Handler4Handler3Handler2],耗时 -> 1609077899391,sleep=3
  16. 3开始1609077899391[pool-1-thread-3]UserEventHandler3 consum -> UserEvent [id=3, name=kevin3, age=13, address=beijing3Handler4Handler2],耗时 -> 1609077899391,sleep=3
  17. 2结束1609077900407[pool-1-thread-2]UserEventHandler2 consum -> UserEvent [id=3, name=kevin3, age=13, address=beijing3Handler4Handler2Handler3],耗时 -> 1609077900407,sleep=2
  18. 2开始1609077900407[pool-1-thread-2]UserEventHandler2 consum -> UserEvent [id=0, name=kevin0, age=10, address=beijing0Handler4],耗时 -> 1609077900407,sleep=2
  19. 3结束1609077902391[pool-1-thread-3]UserEventHandler3 consum -> UserEvent [id=3, name=kevin3, age=13, address=beijing3Handler4Handler2Handler3],耗时 -> 1609077902391,sleep=3
  20. 3开始1609077902391[pool-1-thread-3]UserEventHandler3 consum -> UserEvent [id=0, name=kevin0, age=10, address=beijing0Handler4Handler2],耗时 -> 1609077902391,sleep=3
  21. 2结束1609077902407[pool-1-thread-2]UserEventHandler2 consum -> UserEvent [id=0, name=kevin0, age=10, address=beijing0Handler4Handler2Handler3],耗时 -> 1609077902407,sleep=2
  22. 2开始1609077902407[pool-1-thread-2]UserEventHandler2 consum -> UserEvent [id=2, name=kevin2, age=12, address=beijing2Handler4],耗时 -> 1609077902407,sleep=2
  23. 2结束1609077904422[pool-1-thread-2]UserEventHandler2 consum -> UserEvent [id=2, name=kevin2, age=12, address=beijing2Handler4Handler2],耗时 -> 1609077904422,sleep=2
  24. 2开始1609077904422[pool-1-thread-2]UserEventHandler2 consum -> UserEvent [id=1, name=kevin1, age=11, address=beijing1Handler4],耗时 -> 1609077904422,sleep=2
  25. 3结束1609077905407[pool-1-thread-3]UserEventHandler3 consum -> UserEvent [id=0, name=kevin0, age=10, address=beijing0Handler4Handler2Handler3],耗时 -> 1609077905407,sleep=3
  26. 3开始1609077905407[pool-1-thread-3]UserEventHandler3 consum -> UserEvent [id=2, name=kevin2, age=12, address=beijing2Handler4Handler2],耗时 -> 1609077905407,sleep=3
  27. 2结束1609077906422[pool-1-thread-2]UserEventHandler2 consum -> UserEvent [id=1, name=kevin1, age=11, address=beijing1Handler4Handler2],耗时 -> 1609077906422,sleep=2
  28. 3结束1609077908422[pool-1-thread-3]UserEventHandler3 consum -> UserEvent [id=2, name=kevin2, age=12, address=beijing2Handler4Handler2Handler3],耗时 -> 1609077908422,sleep=3
  29. 3开始1609077908422[pool-1-thread-3]UserEventHandler3 consum -> UserEvent [id=1, name=kevin1, age=11, address=beijing1Handler4Handler2],耗时 -> 1609077908422,sleep=3
  30. 3结束1609077911438[pool-1-thread-3]UserEventHandler3 consum -> UserEvent [id=1, name=kevin1, age=11, address=beijing1Handler4Handler2Handler3],耗时 -> 1609077911438,sleep=3
  31. 1开始1609077911438[pool-1-thread-4]UserEventHandler1 consum -> UserEvent [id=4, name=kevin4, age=14, address=beijing4Handler4Handler3Handler2],耗时 -> 1609077911438,sleep=1s
  32. 1结束1609077912438[pool-1-thread-4]UserEventHandler1 consum -> UserEvent [id=4, name=kevin4, age=14, address=beijing4Handler4Handler3Handler2Handler1],耗时 -> 1609077912438,sleep=1s
  33. 1开始1609077912438[pool-1-thread-4]UserEventHandler1 consum -> UserEvent [id=3, name=kevin3, age=13, address=beijing3Handler4Handler2Handler3],耗时 -> 1609077912438,sleep=1s
  34. 1结束1609077913438[pool-1-thread-4]UserEventHandler1 consum -> UserEvent [id=3, name=kevin3, age=13, address=beijing3Handler4Handler2Handler3Handler1],耗时 -> 1609077913438,sleep=1s
  35. 1开始1609077913438[pool-1-thread-4]UserEventHandler1 consum -> UserEvent [id=0, name=kevin0, age=10, address=beijing0Handler4Handler2Handler3],耗时 -> 1609077913438,sleep=1s
  36. 1结束1609077914454[pool-1-thread-4]UserEventHandler1 consum -> UserEvent [id=0, name=kevin0, age=10, address=beijing0Handler4Handler2Handler3Handler1],耗时 -> 1609077914454,sleep=1s
  37. 1开始1609077914454[pool-1-thread-4]UserEventHandler1 consum -> UserEvent [id=2, name=kevin2, age=12, address=beijing2Handler4Handler2Handler3],耗时 -> 1609077914454,sleep=1s
  38. 1结束1609077915469[pool-1-thread-4]UserEventHandler1 consum -> UserEvent [id=2, name=kevin2, age=12, address=beijing2Handler4Handler2Handler3Handler1],耗时 -> 1609077915469,sleep=1s
  39. 1开始1609077915469[pool-1-thread-4]UserEventHandler1 consum -> UserEvent [id=1, name=kevin1, age=11, address=beijing1Handler4Handler2Handler3],耗时 -> 1609077915469,sleep=1s
  40. 1结束1609077916485[pool-1-thread-4]UserEventHandler1 consum -> UserEvent [id=1, name=kevin1, age=11, address=beijing1Handler4Handler2Handler3Handler1],耗时 -> 1609077916485,sleep=1s

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/254980
推荐阅读
相关标签
  

闽ICP备14008679号