Mongo連接池操縱MongoOptions
MongoOptions
java驅動中,可以在獲取mongo實例時,指定一些參數,如下:
ServerAddress serverAddress=new ServerAddress("127.0.0.1",27017);
MongoOptions mongoOptions=new MongoOptions();
Mongo mongo=new Mongo(serverAddress,mongoOptions);
參數列表如下:
#控制系統在發生連接錯誤時是否重試 ,默以為false --boolean
mongo.options.autoConnectRetry=false
#每個主機答應的連接數(每個主機的連接池大小),當連接池被用光時,會被阻塞住 ,默以為10 --int
mongo.options.connectionsPerHost=10
#multiplier for connectionsPerHost for # of threads that can block if connectionsPerHost is 10, and threadsAllowedToBlockForConnectionMultiplier is 5, then 50 threads can block more than that and an exception will be throw --int
mongo.options.threadsAllowedToBlockForConnectionMultiplier=5
#被阻塞線程從連接池獲取連接的最長等待時間(ms) --int
mongo.options.maxWaitTime
#在建立(打開)套接字連接時的超時時間(ms),默以為0(無窮) --int
mongo.options.connectTimeout=0
#套接字超時時間;該值會被傳遞給Socket.setSoTimeout(int)。默以為0(無窮) --int
mongo.options.socketTimeout=0
#This controls whether or not to have socket keep alive turned on (SO_KEEPALIVE). defaults to false --boolean
mongo.options.socketKeepAlive=false
#Override the DBCallback factory. Default is for the standard Mongo Java driver configuration --DBCallbackFactory
mongo.options.dbCallbackFactory
#//指明是否答應驅動從次要節點或者奴隸節點讀取數據,默以為false --boolean
mongo.options.slaveOk=false
#假如為true,驅動每次update后會發出一個getLastError命令來保證成功,默以為false --boolean
mongo.options.safe=false
#If set, the w value of WriteConcern for the connection is set to this. Defaults to 0; implies safe = true --int
mongo.options.w=0
#If set, the wtimeout value of WriteConcern for the connection is set to this. Defaults to 0; implies safe = true --int
mongo.options.wtimeout=0
#Sets the fsync value of WriteConcern for the connection. Defaults to false; implies safe = true --boolean
mongo.options.fsync=false
java驅動中,可以在獲取mongo實例時,指定一些參數,如下:
ServerAddress serverAddress=new ServerAddress("127.0.0.1",27017);
MongoOptions mongoOptions=new MongoOptions();
Mongo mongo=new Mongo(serverAddress,mongoOptions);
參數列表如下:
#控制系統在發生連接錯誤時是否重試 ,默以為false --boolean
mongo.options.autoConnectRetry=false
#每個主機答應的連接數(每個主機的連接池大小),當連接池被用光時,會被阻塞住 ,默以為10 --int
mongo.options.connectionsPerHost=10
#multiplier for connectionsPerHost for # of threads that can block if connectionsPerHost is 10, and threadsAllowedToBlockForConnectionMultiplier is 5, then 50 threads can block more than that and an exception will be throw --int
mongo.options.threadsAllowedToBlockForConnectionMultiplier=5
#被阻塞線程從連接池獲取連接的最長等待時間(ms) --int
mongo.options.maxWaitTime
#在建立(打開)套接字連接時的超時時間(ms),默以為0(無窮) --int
mongo.options.connectTimeout=0
#套接字超時時間;該值會被傳遞給Socket.setSoTimeout(int)。默以為0(無窮) --int
mongo.options.socketTimeout=0
#This controls whether or not to have socket keep alive turned on (SO_KEEPALIVE). defaults to false --boolean
mongo.options.socketKeepAlive=false
#Override the DBCallback factory. Default is for the standard Mongo Java driver configuration --DBCallbackFactory
mongo.options.dbCallbackFactory
#//指明是否答應驅動從次要節點或者奴隸節點讀取數據,默以為false --boolean
mongo.options.slaveOk=false
#假如為true,驅動每次update后會發出一個getLastError命令來保證成功,默以為false --boolean
mongo.options.safe=false
#If set, the w value of WriteConcern for the connection is set to this. Defaults to 0; implies safe = true --int
mongo.options.w=0
#If set, the wtimeout value of WriteConcern for the connection is set to this. Defaults to 0; implies safe = true --int
mongo.options.wtimeout=0
#Sets the fsync value of WriteConcern for the connection. Defaults to false; implies safe = true --boolean
mongo.options.fsync=false