当前位置: 首页 > news >正文

建网站吧加工网线

建网站吧,加工网线,网站优化包括,wordpress 初始化1.disruptor介绍 什么是 Disruptor? Disruptor 是英国外汇交易公司 LMAX 开发的一个高性能的并发框架。可以认为是线程间通信的高效低延时的内存消息组件#xff0c;它最大的特点是高性能。与 Kafka、RabbitMQ 用于服务间的消息队列不同#xff0c;disruptor 一般用于一个 J… 1.disruptor介绍 什么是 Disruptor? Disruptor 是英国外汇交易公司 LMAX 开发的一个高性能的并发框架。可以认为是线程间通信的高效低延时的内存消息组件它最大的特点是高性能。与 Kafka、RabbitMQ 用于服务间的消息队列不同disruptor 一般用于一个 JVM 中多个线程间消息的传递。从功能上来看Disruptor 实现了“队列”的功能而且是一个有界队列事实上它是一个无锁的线程间通信库。作用与 ArrayBlockingQueue 有相似之处但是 disruptor 从功能、性能上又都远好于 ArrayBlockingQueue。 Disruptor 的优势 Disruptor 最直接的应用场景自然就是“生产者-消费者”模型的应用场合了虽然这些我们使用 JDK 的 BlockingQueue 也能做到但 Disruptor 的性能比 BlockingQueue 提高了 5~10 倍左右也就是说 BlockingQueue 能做的Disruptor 都能做到且做的更好。同时 Disruptor 还能做得更多 2.代码工程 实验目标利用disruptor发送和接收消息 pom.xml ?xml version1.0 encodingUTF-8? project xmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdparentartifactIdspringboot-demo/artifactIdgroupIdcom.et/groupIdversion1.0-SNAPSHOT/version/parentmodelVersion4.0.0/modelVersionartifactIddisruptor/artifactIdpropertiesmaven.compiler.source8/maven.compiler.sourcemaven.compiler.target8/maven.compiler.target/propertiesdependenciesdependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-autoconfigure/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-test/artifactIdscopetest/scope/dependencydependencygroupIdcom.lmax/groupIdartifactIddisruptor/artifactIdversion3.3.4/version/dependencydependencygroupIdorg.projectlombok/groupIdartifactIdlombok/artifactId/dependency/dependencies /project application.yaml server:port: 8088 model package com.et.disruptor.model;import lombok.Data;Data public class MessageModel {private String message; } consumer package com.et.disruptor.event;import com.et.disruptor.model.MessageModel; import com.lmax.disruptor.EventHandler; import lombok.extern.slf4j.Slf4j;Slf4j public class HelloEventHandler implements EventHandlerMessageModel {Overridepublic void onEvent(MessageModel event, long sequence, boolean endOfBatch) {try {Thread.sleep(1000);log.info(consume message start);if (event ! null) {log.info(the message is{},event);}} catch (Exception e) {log.info(consume message fail);}log.info(consume message ending);} } producer package com.et.disruptor.event;import com.et.disruptor.model.MessageModel; import com.lmax.disruptor.EventTranslator; import com.lmax.disruptor.RingBuffer; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.stereotype.Component;/*** author liuhaihua* version 1.0* ClassName HelloEventProducer* Description todo* date 2024年03月29日 13:26*/ Component public class HelloEventProducer {AutowiredRingBufferMessageModel ringBuffer;public synchronized void sayHelloMq(String message){EventTranslatorMessageModel et new EventTranslatorMessageModel() {Overridepublic void translateTo(MessageModel messageModel, long l) {messageModel.setMessage(message);}};ringBuffer.publishEvent(et);}} HelloEventFactory package com.et.disruptor.event;import com.et.disruptor.model.MessageModel; import com.lmax.disruptor.EventFactory;public class HelloEventFactory implements EventFactoryMessageModel {Overridepublic MessageModel newInstance() {return new MessageModel();} } config类 package com.et.disruptor.config;import com.et.disruptor.event.HelloEventFactory; import com.et.disruptor.event.HelloEventHandler; import com.et.disruptor.model.MessageModel; import com.lmax.disruptor.BlockingWaitStrategy; import com.lmax.disruptor.RingBuffer; import com.lmax.disruptor.dsl.Disruptor; import com.lmax.disruptor.dsl.ProducerType; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration;import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors;Configuration public class MqManager {Bean(ringBuffer)public RingBufferMessageModel messageModelRingBuffer() {//define the thread pool for consumer message hander Disruptor touch the consumer event to process by java.util.concurrent.ExecutorSerivceExecutorService executor Executors.newFixedThreadPool(2);//define Event FactoryHelloEventFactory factory new HelloEventFactory();//ringbuffer byte sizeint bufferSize 1024 * 256;//单线程模式获取额外的性能DisruptorMessageModel disruptor new Disruptor(factory, bufferSize, executor, ProducerType.SINGLE, new BlockingWaitStrategy());//set consumer eventdisruptor.handleEventsWith(new HelloEventHandler());//start disruptor threaddisruptor.start();//gain ringbuffer ringto product eventRingBufferMessageModel ringBuffer disruptor.getRingBuffer();return ringBuffer;} } controller package com.et.disruptor.controller;import com.et.disruptor.event.HelloEventProducer; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody;import java.util.HashMap; import java.util.Map;Controller public class HelloWorldController {AutowiredHelloEventProducer helloEventProducer;RequestMapping(/hello)ResponseBodypublic MapString, Object showHelloWorld(){MapString, Object map new HashMap();map.put(msg, HelloWorld);return map;}RequestMapping(/send)ResponseBodypublic String add(String message){helloEventProducer.sayHelloMq(message);return success;}} 启动类 package com.et.disruptor;import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;SpringBootApplication public class DemoApplication {public static void main(String[] args) {SpringApplication.run(DemoApplication.class, args);} } 以上只是一些关键代码所有代码请参见下面代码仓库 代码仓库 https://github.com/Harries/springboot-demo 3.测试 启动Spring Boot应用服务浏览器输入http://127.0.0.1:8088/send?messagehello%20world控制台输出日志 2024-03-29 14:00:54.828 INFO 22784 --- [pool-1-thread-1] c.et.disruptor.event.HelloEventHandler : consume message start 2024-03-29 14:00:54.828 INFO 22784 --- [pool-1-thread-1] c.et.disruptor.event.HelloEventHandler : the message isMessageModel(messagehello world) 2024-03-29 14:00:54.831 INFO 22784 --- [pool-1-thread-1] c.et.disruptor.event.HelloEventHandler : consume message ending 4.引用 https://github.com/LMAX-Exchange/disruptorhttp://www.liuhaihua.cn/archives/710370.htmlhttps://www.jb51.net/article/274145.htm
http://www.pierceye.com/news/19781/

相关文章:

  • 网站 运营工作如何做四川住房建设厅网站首页
  • 有关网站开发的知识wordpress本地搬家到阿里云
  • 网站优化外包免费网站建设链接很长 知呼
  • 青岛市建设局网站停工换接入商网站备案
  • 网站开发工程师薪资网站的优化公司
  • 陕西网站建设多少钱服装设计学院
  • 在线做数据图的网站博客园网站开发
  • 邓州网站推广河南新站关键词排名优化外包
  • 网站备案中是什么意思wordpress上传Flickr
  • 网站背景大小重庆公司seo
  • 做简历的网站 知乎wordpress轻拟物主题
  • 盐城网站建设培训班重庆便民服务网站APP
  • 建设购物网站需要多少费用千阳县住房和城乡建设局网站
  • 网站建设和谷歌优化成都网站优化及推广
  • 软件开发者简称嘉兴优化网站收费标准
  • 关于网站建设培训竞价托管收费标准
  • 网站界面设计有哪些上海网站制作有名 乐云践新
  • 廊坊建站软件文登建设局官方网站
  • 网站路径301重定向怎么做上饶专业的企业网站开发公司
  • 什么样的网站需要改版汕头建筑工程总公司官网
  • 苏州html网站模板wordpress 搬迁插件
  • 如何仿做别人的网站wordpress 定时备份
  • 私人订制旅游网站建设企业邮箱是什么 怎么注册
  • 在线建网站企业网站建设需求调查表
  • 网站制作公司 信科网络湖北网站设计流程
  • 网站开发工程师公司网站卖给别人后做违法信息
  • 可以通过哪些网站注册域名wordpress分类id
  • 路由 拦截 网站开发做企业网站多少钱
  • 不用付费不用登录的网站犀牛云做网站骗人
  • 室内设计效果图网站推荐建设银行大学华东学院网站