首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

高并发讯息处理器

2013-12-30 
高并发消息处理器1. MQEngine?4.M2Queue?import java.util.concurrent.ExecutorServiceimport java.util.

高并发消息处理器


1. MQEngine

?4.M2Queue

?

import java.util.concurrent.ExecutorService;import java.util.concurrent.Executors;import java.util.concurrent.atomic.AtomicLong;import lightmq.MQEngine;import lightmq.MyMessageHandler;/** * MQEngine测试类 * @author kevin * */public class TestMQ {public static void main(String[] args) {final AtomicLong l = new AtomicLong(0);// final MQEngine<String, MyMessageHandler> mq = new MQEngine<String, MyMessageHandler>(10, 50, MyMessageHandler.class);// 模拟客户并发数final int PRODUCER_SIZE = 200000;// 模拟每个客户平均请求次数final int REQUEST_TIME = 10;ExecutorService es = Executors.newFixedThreadPool(10);for (int i = 0; i < PRODUCER_SIZE; i++) {es.execute(new Runnable() {@Overridepublic void run() {for (int i = 0; i < REQUEST_TIME; i++) {mq.push(String.valueOf(l.incrementAndGet()));}}});}try {Thread.sleep(1000);} catch (InterruptedException e) {// TODO Auto-generated catch blocke.printStackTrace();}System.out.println(mq.size());}}

?

热点排行