• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to handle multiple request in Java server side  RSS feed

 
sam liya
Ranch Hand
Posts: 1246
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to write server side program(Servlet) which must be access by several requests at same time.how to handle this using java?
Do i need to use queue or multiple instance of same class.

please find the example server method which returns the results based on ID

 
Abhin Balur
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You dont have to worry about the queuing up the requests. The container(Tomcat for example) will do it for you. The developer of the servlet just has to worry about the what the servlet does/the servlets job. In your case fetching data from the database and returning it.
 
sam liya
Ranch Hand
Posts: 1246
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how do we know that service can handle maximum number of request at a time?can we increase or decrease this amount ?
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's no fixed built-in number which limits how many simultaneous requests a servlet can handle. The actual number depends on the code in the servlet, the power of the computer it's running on, the speed of the network connections, and probably several other factors which I haven't thought of.
 
Abhay Agarwal
Ranch Hand
Posts: 1376
Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
every application server has configuration which allows to set maximum number of active connection limit. you can manipulate it as and when required.
For example Tomcat has two variables - acceptCount and maxThreads value which can be set.
maxThreads allows you to set the maximum number of request processing threads to be created by this Connector, which therefore determines the maximum number of simultaneous requests that can be handled. If not specified, this attribute is set to 200.
acceptCount allows you to set the maximum queue length for incoming connection requests when all possible request processing threads are in use. Any requests received when the queue is full will be refused. The default value is 100.
But remember that Creating a large number of threads and accepting a large number of requests doesn't mean that your server will be able to process the requests efficiently.
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sam liyanage wrote:how do we know that service can handle maximum number of request at a time?


I'm sorry, I didn't really answer this question. If we use the numbers that Abhay described as the "maximum number of requests at a time", you would have to use some kind of stress testing where you set up an application whose purpose was to send more and more simultaneous requests to your server.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
get db connection

In a servlet container, this should mean using a connection pool; Tomcat has one built in: http://tomcat.apache.org/tomcat-7.0-doc/jndi-datasource-examples-howto.html
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!