Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the code examples in Disruptor-07

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report