这个是最新的 disruptor3的例子....来自官方代码稍微简化后的
package io.grass.core.collect; import static com.lmax.disruptor.RingBuffer.createSingleProducer; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.lmax.disruptor.BatchEventProcessor; import com.lmax.disruptor.EventFactory; import com.lmax.disruptor.EventHandler; import com.lmax.disruptor.RingBuffer; import com.lmax.disruptor.SequenceBarrier; import com.lmax.disruptor.YieldingWaitStrategy; import com.lmax.disruptor.util.PaddedLong; /** * 简单测试 * * @author zuoge85 * */ public class DisruptorBaseTest { protected static final Logger log = LoggerFactory.getLogger(DisruptorBaseTest.class); private static final int THREAD_NUMS = 1; private static final int BUFFER_SIZE = 1024 * 8; private static final long NUMS = 1000_000_00L; public static void main(String[] args) throws InterruptedException { RingBuffer<MessageEvent> ringBuffer = createSingleProducer( MessageEvent.EVENT_FACTORY, BUFFER_SIZE, new YieldingWaitStrategy()); ExecutorService executors = Executors.newFixedThreadPool(THREAD_NUMS); SequenceBarrier sequenceBarrier = ringBuffer.newBarrier(); MessageMutationEventHandler[] handlers = new MessageMutationEventHandler[THREAD_NUMS]; BatchEventProcessor<?>[] batchEventProcessors = new BatchEventProcessor[THREAD_NUMS]; for (int i = 0; i < THREAD_NUMS; i++) { handlers[i] = new MessageMutationEventHandler(); batchEventProcessors[i] = new BatchEventProcessor<MessageEvent>( ringBuffer, sequenceBarrier, handlers[i]); ringBuffer .addGatingSequences(batchEventProcessors[i].getSequence()); } CountDownLatch latch = new CountDownLatch(THREAD_NUMS); for (int i = 0; i < THREAD_NUMS; i++) { long n = batchEventProcessors[i].getSequence().get() + NUMS; System.out.println(n +" " +NUMS+" "+batchEventProcessors[i].getSequence().get() ); handlers[i].reset(latch, n); executors.submit(batchEventProcessors[i]); } long start = System.currentTimeMillis(); for (long i = 0; i < NUMS; i++) { long sequence = ringBuffer.next(); ringBuffer.get(sequence).setValue(i); ringBuffer.publish(sequence); } latch.await(); long opsPerSecond = (NUMS * 1000L) / (System.currentTimeMillis() - start); for (int i = 0; i < THREAD_NUMS; i++) { batchEventProcessors[i].halt(); if ((NUMS - 1) == handlers[i].getValue()) { } else { log.error("error"); } } executors.shutdown(); log.info(String.format("Run %d, Disruptor=%,d ops/sec%n", 1, opsPerSecond)); } public static final class MessageMutationEventHandler implements EventHandler<MessageEvent> { private final PaddedLong value = new PaddedLong(); private long count; private CountDownLatch latch; public MessageMutationEventHandler() { } public long getValue() { return value.get(); } public void reset(final CountDownLatch latch, final long expectedCount) { value.set(0L); this.latch = latch; count = expectedCount; } @Override public void onEvent(final MessageEvent event, final long sequence, final boolean endOfBatch) throws Exception { //log.info("onEvent:{}",event.getValue()); value.set(event.getValue()); if (count == sequence) { latch.countDown(); } } } public static final class MessageEvent { private long value; public long getValue() { return value; } public void setValue(final long value) { this.value = value; } public final static EventFactory<MessageEvent> EVENT_FACTORY = new EventFactory<MessageEvent>() { public MessageEvent newInstance() { return new MessageEvent(); } }; } }
相关推荐
Disruptor3.x Disruptor使用方式 EventHandler[] eventHandlers=new DisruptorEventHandler[]{new DisruptorEventHandler()}; DisruptorPublisher dp=new DisruptorPublisher(1024, eventHandlers); dp.start(); ...
Error: java.lang.NoSuchMethodError: com.lmax.disruptor.dsl.Disruptor.<init>(Lcom/lmax/disruptor/EventFactory;ILjava/util/concurrent/ThreadFactory;Lcom/lmax/disruptor/dsl/ProducerType;Lcom/lmax/...
disruptor.jar 2018最新版本(包含disruptor-3.4.1.jar、disruptor-3.4.1-sources.jar、disruptor-3.4.1-javadoc.jar)
disruptor-3.2.0.jar包下载disruptor-3.2.0.jar包下载disruptor-3.2.0.jar包下载
代码为博客实例代码:http://blog.csdn.net/xuemengrui12/article/details/72957338 如有不当之处,请多多指教
disruptor-3.4.4.jar 官方github下载 亲测可用,大家赶紧下载吧 后续再补充其他常用jar(但不好下载的)
disruptor-3.4.2.jar
。。。
。。。
disruptor-3.4.2.jar 工具jar包 及 disruptor-3.4.2-sources.jar, Disruptor它是一个开源的并发框架,并获得2011 Duke’s 程序框架创新奖,能够在无锁的情况下实现网络的Queue并发操作,是 log4j2 引用的 jar 包
disruptor-3.3.11.jar 无锁并行框架 值得学习 jar包
java网络技术示例代码,用于初学者学习 多线程,循环buffer,参考博客上的代码,实现内存的读写功能
java运行依赖jar包
一个基于Java的开源游戏服务器框架实现,使用了Netty、ProtoBuf、Disruptor等
Disruptor框架是由LMAX公司开发的一款高效的无锁内存队列。使用无锁的方式实现了一个环形队列。据官方描述,其性能要比BlockingQueue至少高一个数量级。根据GitHub上的最新版本源码打出的包,希望对大家有帮助。
不错的框架,可以好好研究研究,速度下载,速度下载速度下载速度下载
LMAX是一种新型零售金融交 易平台,它能够以很低的延迟产生大量交易。这个系统是建立在JVM平台上,其核心是一个业务逻辑处理 器,它能够在一个线程里每秒处理6百万订单。...业务逻辑处理器的核心是Disruptor。
注:下文中的 *** 代表文件名中的组件名称。 # 包含: 中文-英文对照文档:【***-javadoc-API文档-中文(简体)-英语-对照版.zip】 jar包下载地址:【***.jar下载地址(官方地址+国内镜像地址).txt】 ...