• Post Reply Bookmark Topic Watch Topic
  • New Topic

Restricting simultaneous requests  RSS feed

 
O. Ziggy
Ranch Hand
Posts: 430
Android Debian VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I have a web application (running on Tomcat) that talks to an Oracle database. I have a problem whereby i would like to restrict the number of simultaneous requests per user.

I run a few tests the other day and i found that if a user refreshes or preses the F5 button several times the application crashes. The main cause for this is that the database denies any more connections as it reaches the maximum number of connections/cursors allowed.

This is probably a matter of increasing the allowed cursors on the database but i would like to solve this from the servlets.

This is what i am thinking of doing..

For each request, i would like to set a flag OutstandingRequest=True and set this to false at the end of the request. Probalbly something like this..



I am hoping that the above example would avoid making several requests to the database in that a request will only be processed if the previous one completed.

Now here is what i would like to know..

1. What do you guys think of the above approach? Is it likely to cause any problems?

2. Is there another way of doing this? probably a more efficient way?

3. Has anyone experiences this problem before? How did you solve it..

I have tried to think if there is another way of doing this and couldnt come up with other tricks.. maybe coz im a beginner in this.. so if anyone can suggest a better approach i would be greatfull.

The only thing taht worries me is what if an exception occurs before the end of the servlet? that would mean that the outstandingRequest flag will not be re-iniitialised thus the user not being able to access the application because it will always be true.

Thanks

[ November 13, 2005: Message edited by: Ziggy Omar ]

[ November 13, 2005: Message edited by: Ziggy Omar ]
[ November 13, 2005: Message edited by: Ziggy Omar ]
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
generally this seems like a good approach. It's definately a good idea to think of these sort of problems early in the design process.

Just a few small suggestions.

First, I'm sure it was just a cut-n-paste error, but surely

//The request is complete now remove the flag
session.setAttribute("outstandingRequest", "true");

should set the attribute to something other than "true"

Second. If you want better performance with just as much readability, you could use a Boolean and a direct comparison rather than a text string and an "equals" for your flag. Something like:



Does that make sense?
 
O. Ziggy
Ranch Hand
Posts: 430
Android Debian VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Yes you are right... it was actually supposed to be

session.setAttribute("outstandingRequest", "false");

I did think about using boolean values but i thought it would give me problems as i would have had to cast the values.

When u declare a value as an "Object" what type is it stored as?
[ November 13, 2005: Message edited by: Ziggy Omar ]
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An Object is stored as an Object.

What I was suggesting was using the built in Boolean objects (that is, objects of class Boolean) Boolean.FALSE and Boolean.TRUE rather than the primitive boolean (note the small "b") values of false and true.

Because these Boolean objects are real objects, they can be stored in any object container (such as a List, a Set, or the session or application context of a web application.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!