如何解决MongoWaitQueueFullException?

sofs1

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

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)

我该如何解决?请帮我。

曼朱纳斯·阿南德

您需要检查设置连接时给出的每主机连接数是多少(查看例外情况,我想您应该将其设置为500)。

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

设置每个主机的连接的理想方法是反复试验,但是您需要通过打开mongo shell并执行以下命令,确保所设置的值不超过可以拥有的连接数:

db.serverStatus()。connections.available

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章