com.mongodb.mongowaitqueuefullexception too many threads are already waiting for a connection
报错信息
com.mongodb.MongoWaitQueueFullException:
Too many threads are already waiting for a connection. Max number of threads (maxWaitQueueSize) of 500 has been exceeded.
原因
本地启动了太多进程,都在请求连接,超过了最大等待连接数,所以需要增加。
在使用异步程序时,要特别注意线程数问题。
方案1
修改连接URI:&waitQueueMultiple=1000&
参考资料:
https://docs.mongodb.com/manual/reference/connection-string/
方案2
MongoClientOptions.Builder builder = new MongoClientOptions.Builder();
builder.connectionsPerHost(1000);
MongoClientOptions options = builder.build();
mongoClient = new MongoClient(URI, connectionOptions);
参考资料:
https://stackoverflow.com/questions/25346951/how-can-i-solve-mongowaitqueuefullexception
MongoDB: java.lang.IllegalStateException: state should be: open
原因
因为MongoDB已经关闭了,但程序还在使用。本次问题出现是因为异步程序在使用连接MongoDB,但没有阻塞,直接到后面的连接池关闭。
参考资料: