MongonDB自学笔记

 

三类Nosql数据库:

解决高并发问题:Redis

解决海量读写问题:MongoDB CouchDB

解决扩展性问题:分布式数据库

 

MongoDB java

MongoDB JAVA 驱动是线程安全的。

MongoClient 内部维护一个线程池实现,池大小默认最大为100

每一次的会话connecton可能是不一样的。

 

DB和DBCollection 也是线程安全的,实际上他们被缓存起来了,不管何种情况,你取到的都是同一个实例。

 

官网原文:http://docs.mongodb.org/ecosystem/drivers/java-concurrency/

The Java MongoDB driver is thread safe. If you are using in a web serving environment, for example, you should create a single MongoClient instance, and you can use it in every request. The MongoClient object maintains an internal pool of connections to the database (default maximum pool size of 100). For every request to the DB (find, insert, etc) the Java thread will obtain a connection from the pool, execute the operation, and release the connection. This means the connection (socket) used may be different each time.

Additionally in the case of a replica set and a read preference of secondary, the read operations will be distributed evenly across all secondaries. This means that within the same thread, a write followed by a read may be sent to different servers (master then slave). In turn the read operation may not see the data just written since replication is asynchronous.

DB and DBCollection are completely thread safe. In fact, they are cached so you get the same instance no matter what.

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值