0

Version 3 of the LMAX Disruptor deprecated the constructor that takes an Executor. So the following gives a compile warning:

Disruptor(eventFactory, bufferSize, Executors.newSingleThreadExecutor())

The new approach uses the ThreadFactory.

How do I instantiate an equivalent Disruptor without causing a warning?

Lukasz G.
  • 119
  • 1
  • 10
  • I don't see why this would be useful. `Executors.newSingleThreadExecutor()` would use one thread for all the event handlers of the disruptor which defeats the point of having multiple event handlers. Otherwise, if you only have one event handler only one thread will be created using `ThreadFactory` which will be equivalent to `Executors.newSingleThreadExecutor()` – Slugart Apr 03 '23 at 23:17
  • I am not sure this is correct. I have analysed the code of the RingBuffer and it seems to create the number of threads equal to the size of the ring buffer - unless I misunderstood/misread. And yes, in my case there is only one event handler. – Lukasz G. Apr 04 '23 at 19:16
  • The `ThreadFactory` is only used here https://github.com/LMAX-Exchange/disruptor/blob/e6f783b22a558ae15e6e835ba9e75de8a9c51238/src/main/java/com/lmax/disruptor/dsl/Disruptor.java#L343 in the `Disruptor` class and as you can see one thread is started per `Consumer` - a `Consumer` is created per `EventHandler` provided to the `Disruptor`. – Slugart Apr 04 '23 at 23:17
  • Where in the `RingBuffer` did you see threads being started / defined? – Slugart Apr 04 '23 at 23:19
  • I see. The code I was referring to is this: https://github.com/LMAX-Exchange/disruptor/blob/e6f783b22a558ae15e6e835ba9e75de8a9c51238/src/main/java/com/lmax/disruptor/RingBuffer.java#L64 But I clearly misread it. I thought it was calling the `threadFactory`, but it calls `eventFactory`. My mistake. – Lukasz G. Apr 06 '23 at 06:19

0 Answers0