Created
December 16, 2015 12:27
-
-
Save sitotkfm/b5bd4e02e2f85d6eb2d5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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