我该如何解决MongoWaitQueueFullException? [英] How can I solve MongoWaitQueueFullException?

查看:784
本文介绍了我该如何解决MongoWaitQueueFullException?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行一个java程序,它是一个线程执行程序,它将数千个文档插入到mongodb中的表中。我收到以下错误

I run a java program which is a thread executor program that inserts thousands of documents to a table in mongodb. I get the following error

Exception in thread "pool-1-thread-301" 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.PooledConnectionProvider.get(PooledConnectionProvider.java:70)
    at com.mongodb.DefaultServer.getConnection(DefaultServer.java:73)
    at com.mongodb.BaseCluster$WrappedServer.getConnection(BaseCluster.java:221)
    at com.mongodb.DBTCPConnector$MyPort.getConnection(DBTCPConnector.java:508)
    at com.mongodb.DBTCPConnector$MyPort.get(DBTCPConnector.java:456)
    at com.mongodb.DBTCPConnector.getPrimaryPort(DBTCPConnector.java:414)
    at com.mongodb.DBCollectionImpl.insert(DBCollectionImpl.java:176)
    at com.mongodb.DBCollectionImpl.insert(DBCollectionImpl.java:159)
    at com.mongodb.DBCollection.insert(DBCollection.java:93)
    at com.mongodb.DBCollection.insert(DBCollection.java:78)
    at com.mongodb.DBCollection.insert(DBCollection.java:120)
    at ScrapResults103$MyRunnable.run(MyProgram.java:368)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
    at java.lang.Thread.run(Thread.java:695)

我该如何解决这个问题?请帮我。

How can I resolve this? Please help me.

推荐答案

您需要检查在设置连接时给出的每个主机值的连接数(查看异常I)我认为你会把它设置为500)。

You need to check what is the connections per host value which you have given while setting up connection (looking at the exception I think you would have set it to 500).

MongoClientOptions.Builder builder = new MongoClientOptions.Builder();
builder.connectionsPerHost(200);
MongoClientOptions options = builder.build();
mongoClient = new MongoClient(URI, connectionOptions);

设置每台主机的连接的理想方法是试错,但你需要确保您设置的值不应超过打开mongo shell并执行的连接数:

An ideal way of setting the connections per host would be by trial and error but you need to make sure that the value which you set should not exceed the number of connections you can have by opening the mongo shell and executing:


db.serverStatus( ).connections.available

db.serverStatus().connections.available

这篇关于我该如何解决MongoWaitQueueFullException?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆