NutzCN Logo
问答 NutzMongo如何设置连接池最大连接数和最大等待队列数
发布于 2547天前 作者 佐蓝 3628 次浏览 复制 上一个帖子 下一个帖子
标签:

使用mongodb时由于线程过多报错,请问怎么加大连接数和等待数

com.mongodb.MongoWaitQueueFullException: Too many threads are already waiting for a connection. Max number of threads (maxWaitQueueSize) of 500 has been exceeded.
	at com.mongodb.connection.DefaultConnectionPool.createWaitQueueFullException(DefaultConnectionPool.java:270) ~[mongo-java-driver-3.2.2.jar:?]
	at com.mongodb.connection.DefaultConnectionPool.get(DefaultConnectionPool.java:89) ~[mongo-java-driver-3.2.2.jar:?]
	at com.mongodb.connection.DefaultConnectionPool.get(DefaultConnectionPool.java:82) ~[mongo-java-driver-3.2.2.jar:?]
	at com.mongodb.connection.DefaultServer.getConnection(DefaultServer.java:72) ~[mongo-java-driver-3.2.2.jar:?]
	at com.mongodb.binding.ClusterBinding$ClusterBindingConnectionSource.getConnection(ClusterBinding.java:86) ~[mongo-java-driver-3.2.2.jar:?]
	at com.mongodb.operation.OperationHelper.withConnectionSource(OperationHelper.java:228) ~[mongo-java-driver-3.2.2.jar:?]
	at com.mongodb.operation.OperationHelper.withConnection(OperationHelper.java:221) ~[mongo-java-driver-3.2.2.jar:?]
	at com.mongodb.operation.BaseWriteOperation.execute(BaseWriteOperation.java:133) ~[mongo-java-driver-3.2.2.jar:?]
	at com.mongodb.operation.BaseWriteOperation.execute(BaseWriteOperation.java:60) ~[mongo-java-driver-3.2.2.jar:?]
	at com.mongodb.Mongo.execute(Mongo.java:781) ~[mongo-java-driver-3.2.2.jar:?]
	at com.mongodb.Mongo$2.execute(Mongo.java:764) ~[mongo-java-driver-3.2.2.jar:?]
	at com.mongodb.DBCollection.executeWriteOperation(DBCollection.java:333) ~[mongo-java-driver-3.2.2.jar:?]
	at com.mongodb.DBCollection.updateImpl(DBCollection.java:495) ~[mongo-java-driver-3.2.2.jar:?]
	at com.mongodb.DBCollection.update(DBCollection.java:455) ~[mongo-java-driver-3.2.2.jar:?]
	at com.mongodb.DBCollection.update(DBCollection.java:432) ~[mongo-java-driver-3.2.2.jar:?]
	at com.mongodb.DBCollection.update(DBCollection.java:522) ~[mongo-java-driver-3.2.2.jar:?]
	at org.nutz.mongo.ZMoCo.update(ZMoCo.java:119) ~[nutzmongo-1.r.60.jar:?]
	at com.nari.nwims.busdown.busin.perf.dao.impl.PerfDaoImpl.mUoISection(PerfDaoImpl.java:35) ~[busDown.jar:?]
	at com.nari.nwims.busdown.busin.perf.DB.PerfService$2.run(PerfService.java:204) [busDown.jar:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895) [?:1.6.0_45]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918) [?:1.6.0_45]
	at java.lang.Thread.run(Thread.java:662) [?:1.6.0_45]
5 回复

用的是1.r.62或者63吗?

建一个类, 并删除mongo.js里面的zMongo定义

@IocBean
public class MongoIocBeanMaker {
	
	@Inject
	protected PropertiesProxy conf;
	
	@IocBean(name="mongoClient")
	public MongoClient createMongoClient() {
		MongoClientOptions.Builder builder = MongoClientOptions.builder();
		builder.maxWaitTime(1500);
		MongoClientOptions clientOptions = builder.build();
		ServerAddress address = new ServerAddress(conf.get("mongo.host"), conf.getInt("mongo.port"));
		return new MongoClient(address, clientOptions);
	}

	@IocBean(name="zMongo")
	public ZMongo createZMongo(@Inject MongoClient client) {
		return ZMongo.me(client);
	}
} 

忘记写连接数

		builder.connectionsPerHost(1000);

修改成功 谢谢兽总

添加回复
请先登陆
回到顶部