简体   繁体   中英

Java Socket Server Stops Responding To All Connections

I have a java socket server, which accepts a connection from the flash client and sends messages to other flash clients connected to the game, it also logs some bits to MySQL database. The server works fine, until the number of clients exceeds ~ 100, then it suddenly stops responding to all connections, It also doesnt accept new connections and only restart makes it work again. The server uses multithreding, so it spawns a new thread for each client. Current physical server has 16 processors & ~ 4gb of RAM (even tho it doesnt use that much). I have tried running the server with -Xms -Xmx -server /etc command line attributes, but nothing helps.

jstack shows nothing unusual (or not that I can see, I can post it if needed as well), except that it gets stuck at the following readByte() in the server thread part of the code (line 59):

while(((cr = streamIn.readByte()) != EOF))
    {
     if(amount < 100)
     {
      a+=(char)cr;
      amount++;
     }
     else
      break;
    }

EDIT: Apparently no need to have all the code - its readByte() that actively blocks, when it gets a EOF exception. Wil ask another question now on how to fix it.

Quick guess:

Quick shot would be that you are reaching 100 connections limit to DB. See more - http://dev.mysql.com/doc/refman/5.5/en/too-many-connections.html

Some general hints:

  • try use ExecutorService for thread management,
  • use NIO,
  • verify if db connection is closed

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM