On 27/08/2013 03:40, Vince Stewart wrote: > hi all, > thought I would add some progress on this topic. > I have changed my method for reading from the HttpServletRequest object but > the same warning message is thrown for every 8192 bytes read. I no longer > regard my code to be suspect though am happy to be corrected. The > application operates completely normally except for the warning message. The > code I am using to read the input is shown below. > > public void doPost(HttpServletRequest httpServletRequest.....etc > .......other code.............. > char[] cbuf=new char[8192]; > int i=0; > int requestLength=httpServletRequest.getContentLength(); > BufferedReader in=httpServletRequest.getReader(); > StringBuilder sb=new StringBuilder(requestLength); > while(sb.length()<requestLength){ > if(in.ready()){ > i=in.read(cbuf,0,reqLen); > } > sb.append(cbuf,0,i); > } > in.close(); > String message=sb.toString(); > //.....etc
It looks like there is a possible Tomcat bug but the above code is not the way to read data from the client as it puts the thread into a tight loop while it is waiting for more data to arrive. You'd be better off dropping the call to in.ready() and doing a blocking read on the socket. The elapsed time should be the same (might even be a little less) and your CPU consumption during the read when the client is slow sending data will be significantly lower. If you remove the call to in.ready(), I'm fairly sure you'll see the warnings disappear. Ideally, you should look at non-blocking IO as supported by Servlet 3.1 but that might be too big a change as it fundamentally changes how data is read and written. Mark --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org