Note that there are some explanatory texts on larger screens.

plurals
  1. POAn infinite loop somewhere in my code
    primarykey
    data
    text
    <p>I have this Java game server that handles up to 3,000 tcp connections, each player, or each tcp connection has its own thread, each thread goes something like this:</p> <pre><code>public void run() { try { String packet = ""; char charCur[] = new char[1]; while(_in.read(charCur, 0, 1)!=-1 &amp;&amp; MainServer.isRunning) { if (charCur[0] != '\u0000' &amp;&amp; charCur[0] != '\n' &amp;&amp; charCur[0] != '\r') { packet += charCur[0]; }else if(!packet.isEmpty()) { parsePlayerPacket(packet); packet = ""; } } kickPlayer(); }catch(IOException e) { kickPlayer(); }catch(Exception e) { kickPlayer(); } finally { try{ kickPlayer(); }catch(Exception e){}; MainServer.removeIP(ip); } } </code></pre> <p>The code runs fine, and I know that each thread for each player is a bad idea, but I'll have too keep it this way for now. The server runs fine on a fast machine (6cor x2, 64bits, 24GB RAM, Windows Server 2003).</p> <p>But at some point, after about 12 hours of UpTime, the server starts to loop somewhere... I know that because the java process takes 99% of the CPU infinitely until the next reboot. And I'm having hard time to profile the application because I don't want to disturb the players. The profiler I use (visualvm) always end up chashing the server without telling me where's the problem. </p> <p>Anyways, in that piece of code above I think maybe the problem comes from this: </p> <pre><code>while(_in.read(charCur, 0, 1)!=-1) </code></pre> <p>(the <code>_in</code> is a <code>BufferedReader</code> of the client's socket).</p> <p>Is it possible that <code>_in.read()</code> can return something else infinitely that will keep my code runing and taking 99% of ressources? Is there something wrong with my code? I don't understand everything, I only wrote half of it. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload