Вопрос

I'm looking at a servlet in which we make use of the KXML2 serializer.

I have seen that the previous developer calls flush() quite often... except for having the data sent faster to the client, what effect is there on the actual server and tomcat?

Would the CPU usage/load be less when not using flush?

I've benchmarked/profiled using VisualVM and seen that my code runs faster without the flush.

Finally, pros/cons anything I should worry about...

Это было полезно?

Решение

except for having the data sent faster to the client, what effect is there on the actual server and tomcat?

It makes them do more work.

Would the CPU usage/load be less when not using flush?

Slightly, yes. The flush() itself costs CPU cycles, and also possible network delays. There really isn't much point, as the client can't do much until it has the complete response anyway. If the response isn't chunked or fixed-length, Tomcat has to buffer it all anyway to get the Content-length: anyway before sending it, in which case there is no advantage whatsoever.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top