java - BufferedReader.read() eating 100% of CPU -
I have a Java server that uses 1 TPP per connection. (I know this is bad, but I still have to keep it this way). (3.2GHz 6cor x2 machine, 24GB RAM, Windows Server 2003 64 bit) and here's a piece of code:
Public Zero Run (try {string {/ pic} Char charCur [] = New four [1]; While (_in.read (charCur, 0, 1)! = - 1 & amp; amp; server server.ring) {if (charCur [0]! = '\ U0000' & amp; amp; Amp; amp; amp; amp; amp; amp; amp; amp; four; Cur [0]! = '\ N' and & amp; charcoal [0]! = '\ R') {Packet + = Charchur [0]; } And if (! Packet.isEmpty ()) {parsePlayerPacket (packet); Packet = ""; }}} Hold (exception e) {e.printStackTrace (); } Finally {try} kickplayer (); } Hold (exception e) {e.printStackTrace ();}; Server.removeIp (_ip); After about 12 hours or more of server uptime (and linked to about 3,000 players) the server starts to eat 99% of all 12 CPUs, unless I manually reboot the Java Abrasson. Therefore the game starts and my players start complaining. I have tried the outline of the application and here it is that I came with:
So I think the problem is coming from:
while (_in.read (charCur) , 0, 1)! = - 1 & Server Server .isRunning) Knowing that "_in" is the reader of the variable socket Input: (_in = New BufferedReader (New InputStreamReader) (_socket.getInputStream ()). Why long after the server upTime _in.read () on the earth so much Pu?
I have tried to insert thread soda (1); while inside more loop but nothing does, I think the problem is inside the BufferedReader.read () method.
Can anyone know what might be the reason for this? And how to fix it?
This is a duplicate of your previous question: Please open a new question, but use the editing function instead.
It is being said that, 3000 formulas are definitely very high and due to this the reason for the excessive amount of reference switching will be the reason. Instead of starting a new thread for each connection, consider using non-blocked IO features in Java. Examples can be found here:
Comments
Post a Comment