注:接收不需要连接池,而发送需要连接池,是因为,接收在启动项目时就要注册监听,数目是固定的,而发送则会随着时间数目不断在变动,需要连接池,性能更优。
重点代码:
private static void initMQObjectPool() {
private static Map<String, GenericObjectPool<MQObject>> mqObjectPool = new ConcurrentHashMap<String, GenericObjectPool<MQObject>>(100);
MQObjectFactory factory = new ActiveMQObjectFactory(bean.getBrokerId());
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
config.setMaxTotal(MaxTotal());
config.setBlockWhenExhausted(BlockWhenExhausted());
config.setMaxWaitMillis(MaxWaitMillis());
config.setNumTestsPerEvictionRun(NumTestsPerEvictionRun());
config.setTestOnBorrow(TestOnBorrow());
config.setTestOnReturn(TestOnReturn());
config.setTestWhileIdle(TestWhileIdle());
config.setTimeBetweenEvictionRunsMillis(TimeBetweenEvictionRunsMillis());
config.setMinEvictableIdleTimeMillis(MinEvictableIdleTimeMillis());
GenericObjectPool<MQObject> pool = new GenericObjectPool<MQObject>(factory, config);
mqObjectPool.put(bean.getBrokerId(), pool);
}
}