我有一個聊天應用程序(套接字編程),考慮到我有2個單獨的聊天服務器'Server1'&'Server2'。 我正在使用2個聊天服務器來進行負載均衡(Lvs)。我的LVS工作正常。客戶端如何處理「無法創建新的本地線程異常」在客戶端
例如:當1000個用戶一次嘗試登錄時,在LVS的影響下,500個請求轉到'server1',另外500個轉到'server2'。
這裏來我的問題:在「客戶端」
Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: unable to create new native thread
:當我嘗試登錄了5000個用戶,圍繞4850成功登錄後,我得到的錯誤。
我該如何處理?
僅供參考:我正在使用新固定線程池, 這裏是我在服務器端和客戶端使用的登錄部分。
在服務器端:
ExecutorService executorService = Executors.newFixedThreadPool(400);
while(true){
s = ss.accept();
}
在登錄方面
for(int i=startc;i<endc;i++) // here for e.g if we want to login 1000 users, startc value =1 and endc value=1000.
{
ChatClient.chatHandler = new ChatClient("users"+i);
}
ChatClient {
public ChatClient(String username)
{
Chatclient = this;
this.username = username;
LoginChatConnect();
}
}
void LoginchatConnect(){
try{
sockChatListen = new Socket(URLstore.serverSocket,URLstore.ChatPort); // chatPort=5004,serverSocket=server Ip address.
}catch (IOException e) {
System.out.println("IOException in LoginChat "+e);
}
}
任何建議將是有益的。
我不明白你的問題。你是問客戶應該如何處理服務器內存不足的問題?我不確定它有可能,因爲它不會得到有關這種失敗的通知。 – Gray 2012-04-02 15:11:11
是的,在客戶端我想避免這種異常。意味着有辦法處理這種情況。 – Java 2012-04-02 15:22:23
客戶端或服務器端發生異常嗎?哪個VM耗盡內存?這不是你可以「處理」的東西。 – Gray 2012-04-02 15:25:06