public class Event { private String data; public void setData(String data) { this.data = data; } public String getData() { return data; } } public class EventHandler implements EventHandler<Event> { @Override public void onEvent(Event event, long sequence, boolean endOfBatch) throws Exception { System.out.println("Event data: " + event.getData()); } } public class EventFactory implements EventFactory<Event> { @Override public Event newInstance() { return new Event(); } } int bufferSize = 1024; Disruptor<Event> disruptor = new Disruptor<>(new EventFactory(), bufferSize, Executors.defaultThreadFactory()); EventHandler eventHandler = new EventHandler(); disruptor.handleEventsWith(eventHandler); RingBuffer<Event> ringBuffer = disruptor.start(); EventProducer producer = new EventProducer(ringBuffer); producer.sendEvent("Hello, Disruptor!"); disruptor.shutdown();


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