Disruptor实例

编写过程:
1.Event类(数据对象)

public class LongEvent{ }

2.建立一个生产数据的工厂类,EventFactory,用于生产数据。
 实现EventFactory.
public class LongEventFactory implement EventFactory { }

3.生产者类
public class LongEventProducer{ }
4.消费者类(监听事件类,处理Event数据)
public class LongEventHandler  implements  EventHandler{ }

5.入口程序

  5.1 创建缓冲池

ExecutorService executor=Executors.newCachedThreadPool();
  5.2 创建工厂(第二步实例化)

LongEventFactory factory=new LongEventFactory();
  5.3 创建Disruptor/ 连接消费事件/启动/发布事件/关闭Disruptor/关闭disruptor线程池

Disruptor disruptor=new Disruptor<>(factory, ringBufferSize, executor,ProducerType.SINGLE,new YieldingWaitStrategy());

   public class LongEventMain{}


学习教程:
1.http://www.cnblogs.com/sigm/p/6251910.html (架构师养成记)
2.http://ifeve.com/disruptor/ (API)
3.https://github.com/LMAX-Exchange/disruptor(官方)

本内容由安康学院“雨季”原创。

 

 

你可能感兴趣的:(java小程序)