Skip to content

Instantly share code, notes, and snippets.

@sitotkfm
Created December 16, 2015 12:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sitotkfm/b5bd4e02e2f85d6eb2d5 to your computer and use it in GitHub Desktop.
Save sitotkfm/b5bd4e02e2f85d6eb2d5 to your computer and use it in GitHub Desktop.
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