Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What are the code examples in Disruptor-07

Shulou Source: shulou.com Published: 2022-06-02 10:26:19 09月25日 Update

This article will explain in detail what code examples are in Disruptor-07, and the content of the article is of high quality, so the editor will share it for you as a reference. I hope you will have some understanding of the relevant knowledge after reading this article.

Public class Test {private static Logger logger = LogManager.getLogger (); @ SuppressWarnings ("unchecked") public static void main (String [] args) throws InterruptedException {/ / The factory for the event TestEventFactory factory = new TestEventFactory (); / / Specify the size of the ring buffer, must be power of 2. Int bufferSize = 1024 / Construct the Disruptor Disruptor disruptor = new Disruptor (factory, bufferSize, DaemonThreadFactory.INSTANCE, ProducerType.SINGLE, new BlockingWaitStrategy ()); / / Create EventHandler TestEventHandler handler1 = new TestEventHandler ("handler1"); TestEventHandler handler2 = new TestEventHandler ("handler2"); TestEventHandler handler3 = new TestEventHandler ("handler3") TestEventHandler handler4 = new TestEventHandler ("handler4"); / / Connect the handler int count = 100; / / Unicast is in WorkPool mode, and the three WorkHandler are executed a total of 100 times. / / when Event arrives, which WorkHandler is scheduled is uncertain. / / disruptor.handleEventsWithWorkerPool (handler1, handler2, handler3); / / MulticastTest concurrent processing method: 3 EventHandler, each executed 100 times for a total of 300 times; / / when each Event arrives, the processing order of the EventHandler is uncertain. / / concurrent (handler1, handler2) Handler3) / / EventHandler:handler1--85:k-v / / EventHandler:handler3--85:k-v / / EventHandler:handler2--85:k-v / / EventHandler:handler1--86:k-v / / EventHandler:handler3--86:k-v / / EventHandler:handler2--86:k -v handler3 / / EventHandler:handler1--97:k-v / / EventHandler:handler2--97:k-v / / EventHandler:handler3--97:k-v / / EventHandler:handler1--98:k-v / / EventHandler:handler2--98:k-v / / EventHandler:handler3--98: KMurv / / EventHandler:handler1--99:k-v / / EventHandler:handler2--99:k-v / / EventHandler:handler3--99:k-v / / EventHandler:handler1--100:k-v / / EventHandler:handler2--100:k-v / / EventHandler:handler3--100: KMurv / / disruptor.handleEventsWith (handler1) .handleEventsWith (handler2) .handleEventsWith (handler3) / / Diamond / / schedule disruptor.handleEventsWith (handler1) .handleEventsWith (handler2,handler3) .handleEventsWith (handler4) according to handler1- > concurrent (handler2, hander3)-> handler4; / / Start the Disruptor, starts all threads running disruptor.start (); / / Get the ring buffer from the Disruptor to be used for publishing. RingBuffer ringBuffer = disruptor.getRingBuffer (); TestEventProducer producer = new TestEventProducer (ringBuffer); for (int I = 1; I

Tags: Code examples content articles methods more knowledge articles order processing scheduling good quality reference help related Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Shulou Tech Info macOS Microsoft Huawei