Hi Mark, a bit more follow-up on accessing the servlet InputStream: You advised "You'd be better off dropping the call to in.ready() and doing a blocking read on the socket.....If you remove the call to in.ready(), I'm fairly sure you'll see the warnings disappear."
I just thought I'd let you know, that prediction was absolutely correct. On Thu, Aug 29, 2013 at 7:09 AM, Vince Stewart <stewart.vi...@gmail.com>wrote: > Appreciate this a lot Mark. > > I'm pretty sure my previous code had a short sleep in each loop but > thankfully, in-coming data rarely exceeds the Servlet InputBuffer size of > 8192 so looping is rare. > > I have been trying to get to grips with the asynchronous stuff but have > not got it going yet. The concept is very appealing. Thanks for your > contributions. > > > On Wed, Aug 28, 2013 at 11:00 PM, Mark Thomas <ma...@apache.org> wrote: > >> On 28/08/2013 09:41, Mark Thomas wrote: >> > 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. >> >> I've just cleaned up the code for Tomcat 8.0.x to fix the bug that your >> example highlighted. Thanks for such a clear problem statement that made >> it very easy to track down the root cause of the issue. The fix will be >> in 8.0.0-RC2 onwards. >> >> That said, my comments about there being a better way to do what you are >> doing stand. >> >> Mark >> >> > >> > 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 >> > >> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org >> For additional commands, e-mail: users-h...@tomcat.apache.org >> >> > > > -- > Vince Stewart > -- Vince Stewart