0 http://blog.csdn.net/mydeman/article/details/6652387

1 MongoDB 内置连接池,不需要使用额外的连接池驱动

Note: The Mongo object instance actually represents a pool of connections to the database; you will only need one object of class Mongo even with multiple threads.  See the concurrency doc page for more information.

The Mongo class is designed to be thread safe and shared among threads. Typically you create only 1 instance for a given DB cluster and use it across your app. If for some reason you decide to create many mongo intances, note that:

  • all resource usage limits (max connections, etc) apply per mongo instance
  • to dispose of an instance, make sure you call mongo.close() to clean up resource

2 连接池配置如下:

  内置连接池有多个重要参数,分别是:

    • connectionsPerHost:每个主机的连接数
    • threadsAllowedToBlockForConnectionMultiplier:线程队列数,它以上面connectionsPerHost值相乘的结果就是线程队列最大值。如果连接线程排满了队列就会抛出“Out of semaphores to get db”错误。
    • maxWaitTime:最大等待连接的线程阻塞时间connectTimeout:连接超时的毫秒。0是默认和无限
    • socketTimeout:socket超时。0是默认和无限
    • autoConnectRetry:这个控制是否在一个连接时,系统会自动重试

其设置方式如下:

MongoOptions opt = mongo.getMongoOptions();
opt.connectionsPerHost = 10 ;//poolsize
opt.threadsAllowedToBlockForConnectionMultiplier = 10;

最新文章

  1. JAVA学习心得
  2. lua创建文件和文件夹
  3. hdu 4452
  4. Puppent 基本使用方法
  5. openfire当中的Custom Database Integration Guide的配置
  6. CSS基础知识(颜色、伪类、盒子模型)
  7. 剑指Offer-不用加减乘除做加法
  8. 使用C++实现图形的旋转、缩放、平移
  9. springdata 多对多配置
  10. 数据结构C语言版-队列
  11. salesforce零基础学习(九十二)使用Ant Migration Tool 实现Metadata迁移
  12. Mac CLion下OpenGL环境配置
  13. 让sublime可以和visual studio一样自动在运算符前后添加空格的插件
  14. Qt5.7 无法输入中文问题
  15. 【代码笔记】iOS-给密码进行加密
  16. python startswith() 函数
  17. 数据结构-队列(3)-使用Java内置队列
  18. 《流畅的python》读书笔记
  19. 为同一部电脑设置2个IP地址
  20. Android——FileOutputStream与openFileOutput()的区别分析【第一个用于文件存储,第二个用于SD卡存储】【转】

热门文章

  1. Yii2的一些问题
  2. PHP ftp_fput() 函数
  3. 「题解」:$Six$
  4. 线段树双tag+差分数组——cf1208E
  5. Vue源码------------- 数据响应系统的基本思路
  6. 剑指offer——丑数(c++)
  7. targetSdkVersion和与target属性的区别
  8. C#中的this关键字
  9. 第一章 Linux是什么
  10. Ubuntu终端内打开文件管理器