Restrict REST service 100 request only

Viewed 98

Recently in a Java interview I had a question for REST service.

The interviewer asked me to restrict REST service to serve only 100 request parallel for any user. If more than 100 requests arive then they should wait (any waiting response).

Any suggestions for this question, on how can we achieve to restrict our REST service ?

1 Answers

In the theory you will have to limit the number of thread used for processing the requests to 100. And in the same time have a number of connection TCP available superior to 100.

After that the request processing thread have to take open connection TCP one after another. That sound hard but springboot come to your rescue.

According to this blog if you user tomcat-embed you will have have to set 2 properties in your configuration :

maxThreads: 100
acceptCount: The number of connection who can wait the liberation of a thread
Related