我想学Disruptor framework。谁能给我一个用Java编程语言在main方法中运行的helloworld示例?
发布于 2013-01-24 13:07:46
下面是一个简单的、可运行的示例,说明如何使用Disruptor库。示例是使用Disruptor库的2.10.4版编写的。
https://github.com/trevorbernard/disruptor-examples
我也在这个帖子上交叉发帖:The simplest and actual example code of LMAX Disruptor
发布于 2014-01-14 14:38:52
这是我这边的另一个。我尝试了一个使用开源Lmax库的disruptor示例。
我认为使用lmax disruptor (而不是disruptor的内部)背后的想法是创建消息分派器并像消费者一样注册事件侦听器。
通过指定消息类型,您可以创建。
Disruptor<Message> disruptor = new Disruptor<Message>(Message.EVENT_FACTORY, 2048, exec);`您可以创建处理程序
final EventHandler<Message> handler = new EventHandler<Message>() {
// event will eventually be recycled by the Disruptor after it wraps
public void onEvent(final Message event, final long sequence, final boolean endOfBatch) throws Exception {
Integer value = event.getMsg();
if(value % 10000 == 0){
System.out.println("ValueEvent: " + value + " Sequence: " + sequence);
double timeINnanos = (System.nanoTime()-startTime);
double timetaken = (timeINnanos/1e9);
System.out.println("Time Taken till now in sec " + timetaken );
}
}
};使用disruptor注册处理程序
disruptor.handleEventsWith(handler);启动中断程序并将返回RingBuffer传递给生产者
RingBuffer<Message> ringBuffer = disruptor.start();
Producer producer = new Producer(ringBuffer);完整的代码可以在这里找到Github link
发布于 2016-01-11 15:59:31
我建议您查看LMAX代码LMAX Source Code Test Directory 中的测试目录。在我看来,它是你可以用LMAX做的所有事情的最好来源。对于简单的示例,请查看以下链接Simple Example
我还建议你看看DSL examples.
https://stackoverflow.com/questions/9826512
复制相似问题