Hi, I'm looking for ideas/suggestions/patterns about limiting concurrent requests by user. May be you have tackled this kind of problem previously and I'd like to heard your opinions.
I've a web service. In order to do a request, a user specifies a username and password via web service parameters along with web service parameters. The web service server, checks user and password and if it is correct, then process the request (else response "access denied"). The process may take some seconds or a few minutes to be completed. I'd like to limit the number of client requests per user. I'm thinking to mantain some data structure in memory (shared by all tomcat threads, I don't know how to do that) or in some table in the database to count the number of requests per user. For each received request, if accepted, increments the counter, and when the process finishes (or if the process fails) decrements the counter. In order to do that, I think I need to have a singleton class and a synchronized method to check and modify the counter. Sincerely, I don't think it's a good idea, because I'll have a bottleneck using synchronized methods. In other hand, I don't know and I'd like: - how to or where to place and access an object shared by all tomcat threads - define a singleton class in tomcat And I'd like to have a solution that can be extended to many tomcat instances (in different servers). I'm using: Tomcat 7.0.14 Metro 2.0 (jax-ws) MySQL + Hibernate Do you have any suggestion? Thanks in advance HernĂ¡n