@Data
public class Trade {
private String id;
private String name;
private double price;
private AtomicInteger count = new AtomicInteger(0);
}
2.1.2、创建提交任务的方式
public class TradePublisher implements Runnable {
private Disruptor<Trade> disruptor;
private CountDownLatch latch;
private static int PUBLISH_COUNT = 1;
public TradePublisher(CountDownLatch latch, Disruptor<Trade> disruptor) {
this.disruptor = disruptor;
this.latch = latch;
}
/**
* When an object implementing interface <code>Runnable</code> is used
* to create a thread, starting the thread causes the object's
* <code>run</code> method to be called in that separately executing
* thread.
* <p>
* The general contract of the method <code>run</code> is that it may
* take any action whatsoever.
*
* @see Thread#run()
*/
@Override
public void run() {
TradeEventTranslator eventTranslator = new TradeEventTranslator();
for(int i=0; i<PUBLISH_COUNT; i++){
// 新的提交任务的方式
disruptor.publishEvent(eventTranslator);
}
latch.countDown();
}
class TradeEventTranslator implements EventTranslator<Trade>{
private Random random = new Random();
@Override
public void translateTo(Trade event,