2012-06-18 67 views
0

我正在使用MongoDB存儲數據。在我的項目中,我使用線程池將多個用戶(100-2000個用戶)連接到服務器,並將這些用戶的響應存儲在數據庫中。但是當我這樣做時,我得到這個錯誤。請幫我解決一下這個。我無法得到它。我已經浪費了45小時這個錯誤。使用mongodb與java時出錯

錯誤:

java.lang.reflect.InvocationTargetException 
    at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
    at java.lang.reflect.Method.invoke(Method.java:597) 
    at com.avaya.onex.hss.requesthandlers.CommandExecutor.executeCommands(CommandExecutor.java:129) 
    at com.avaya.onex.hss.requesthandlers.CommandExecutor.run(CommandExecutor.java:59) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) 
    at java.lang.Thread.run(Thread.java:662) 
Caused by: com.mongodb.DBPortPool$SemaphoresOut: Out of semaphores to get db connection 
    at com.mongodb.DBPortPool.get(DBPortPool.java:176) 
    at com.mongodb.DBTCPConnector$MyPort.get(DBTCPConnector.java:370) 
    at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:149) 
    at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:138) 
    at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:261) 
    at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:211) 
    at com.mongodb.DBCollection.insert(DBCollection.java:57) 
    at com.mongodb.DBCollection.insert(DBCollection.java:102) 
    at com.avaya.onex.hss.objects.LoginRequest.storeData(LoginRequest.java:152) 
    at com.avaya.onex.hss.requesthandlers.LoginHandler.handleRequest(LoginHandler.java:20) 
    ... 8 more 
com.mongodb.DBPortPool$SemaphoresOut: Out of semaphores to get db connection 
    at com.mongodb.DBPortPool.get(DBPortPool.java:176) 
    at com.mongodb.DBTCPConnector$MyPort.get(DBTCPConnector.java:370) 
    at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:212) 
    at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:305) 
    at com.mongodb.DB.command(DB.java:160) 
    at com.mongodb.DB.command(DB.java:183) 
    at com.mongodb.DB.command(DB.java:144) 
    at com.mongodb.DBCollection.drop(DBCollection.java:777) 
    at com.mongodb.DBApiLayer$MyCollection.drop(DBApiLayer.java:206) 
    at com.avaya.onex.hss.requesthandlers.CommandExecutor.executeCommands(CommandExecutor.java:118) 
    at com.avaya.onex.hss.requesthandlers.CommandExecutor.run(CommandExecutor.java:59) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) 
    at java.lang.Thread.run(Thread.java:662) 
+0

你是否檢查過MongoDB源代碼,尤其是'DBPortPool'類? –

+0

不,讓我現在檢查.. – shalki

+0

我只有那個jar文件..在哪個DBPortPool類存在...我怎樣才能讀取java源.. – shalki

回答

2

嘗試增加連接池中的連接數。

here,在connectionsPerHost。

+0

這可能是解決它的正確方法。還有一些可能相關的[threadsAllowedToBlockForConnectionMultiplier](http://api.mongodb.org/java/2.4/com/mongodb/MongoOptions.html#threadsAllowedToBlockForConnectionMultiplier)。但是,也許shalki已經發現並且在一週的故障排除之後已經嘗試過了? –

+0

是的..我也試過。這不是在增加這個工作。發生同樣的錯誤。 – shalki

+0

如果您將connectionsPerHost設置爲與您的線程池一樣大的值,那麼您應該永遠不會收到您現在得到的錯誤。 – jyemin