<dependency> <groupId>com.lmax</groupId> <artifactId>disruptor</artifactId> <version>3.4.2</version> </dependency> public class Event { private String data; } public class EventHandler implements EventProcessor { @Override public void processEvent(Event event, long sequence, boolean endOfBatch) { } } public class EventFactory implements EventFactory<Event> { @Override public Event newInstance() { return new Event(); } } WaitStrategy waitStrategy = new BlockingWaitStrategy(); Disruptor<Event> disruptor = new Disruptor<>(new EventFactory(), bufferSize, executor, ProducerType.SINGLE, waitStrategy); disruptor.handleEventsWith(new EventHandler()); disruptor.start(); RingBuffer<Event> ringBuffer = disruptor.getRingBuffer(); long sequence = ringBuffer.next(); Event event = ringBuffer.get(sequence); event.setData("Hello, Disruptor!"); ringBuffer.publish(sequence);


上一篇:
下一篇:
切换中文