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: [email protected]
> For additional commands, e-mail: [email protected]
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]