Though right solution will depend upon the fesibility of your application requirement, following might be helpful:
When Q is full instead of blocking indefinitely, block with timeout
so as servlet will return response in a fix configured time. In case of timeout
, servlet can throw server-busy kind of custom error message or related HTTP-CODE
.
Since your consumer is slow and producer is very fast, you might as well consider increasing consumer threads so as to allow lesser blocking experience to servlet caller.
Also, accepting all request (ie storing into a unbounded-Q) wouldn't be a nice solution as (depending upon request size) due to slow consumer Q, over period of time might consume huge memory..