Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
public class DisruptorTest1 {
public static void main(String[] args) throws InterruptedException {
Executor executor = Executors.newCachedThreadPool();
int bufferSize = 1024;
Disruptor<LongEvent> disruptor = new Disruptor<>(LongEvent::new, bufferSize, executor, ProducerType.MULTI, new SleepingWaitStrategy());
disruptor.handleEventsWith(
(event, sequence, endOfBatch) -> {
System.out.println("Event1: " + event.get() + ",currentTimeMillis:" + System.currentTimeMillis());
Thread.sleep(1000);
}
);
disruptor.start();
RingBuffer<LongEvent> ringBuffer = disruptor.getRingBuffer();
LongEventProducerWithTranslator producer = new LongEventProducerWithTranslator(ringBuffer);
ByteBuffer bb = ByteBuffer.allocate(8);
for (long l = 0; true; l++) {
bb.putLong(0, l);
ringBuffer.publishEvent(
(event, sequence, buffer) -> event.set(buffer.getLong(0)),
bb);
Thread.sleep(1000);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment