Servlets handle multiple, concurrent requests

Hi, folks. Could someone give me a basic idea of how Servlets handle multiple, concurrent requests which are sent from user's web browser, or possibly, point me some useful web links, tutorials. Let me take a example to make sure that i have explained the question clearly: let's say there is a website that does air ticket booking service. Suppose there is a spare seat exists for a particular flight. There are two users logon to the website and they are both looking for this particular seat. So, once these user's HTML form requests are sent to server, how do i implement my servlet to handle these requests properly, in another words, make sure this seat is only allowed booked by a single user. thanks in advance.

This acturally raises me a another question which i
still have some uncertainties. In another assignment i
did last semester, that was we had multiple users
using our database and accessing, retirving and
updating database by using jdbc. And what i did was
let every user call a particular method within a
javabean for setting up database connection, then goes
for the specific that needs to be dealt with. So, what
i am wondering now is that can i possibly having a
different approach, like setting up only a single
connection(ie. a public Connection objec) which being
exist all the time so that all request can get
connection by calling this object's relevant method.
Hope i explained it clearly.
If I understand you correctly, then you would have to make the methods of this Connecting Object synchronized so that there was only ever one connection to the database at any one time.
If a database is transactional, that means it has attempted to deal with the problem of multiple connections and statements being executed at the same time on the same data. If you have one single Connecting Object then you don't have to worry about transactions, but you do need to make sure that there aren't multiple threads running, each trying to use your Connecting Object.
The synchronized keyword makes sure only one thread can use the synchronized method at any one time.

Similar Messages

  • How to handle multiple SOAP requests for ArrayCollection initialization?

    Hello.
    I want to initialize some ArrayCollection with objects, which receive field values via SOAP requests (in getUdfValuePrj function).
    for (var i:int=0; i < data.length; i++)
      var task:Task=new Task();
      task.laborio = getUdfValuePrj(data[i].id, LABORIOUSNESS);
    tempTaskArray.addItem(task);
    Here is my WebService:
    private function initWebServices(wsdl:String):void
      _udfWs = new WebService();
      _udfWs.wsdl = wsdl;
      _udfWs.getTaskUDFValue.addEventListener("result",
      getTaskUDFValueResult);
      _udfWs.getTaskUDFValue.addEventListener("fault", handleFault);
      _udfWs.loadWSDL();
    The question is, how functions getUdfValuePrj and getTaskUDFValueResult should look like?
    I think that is no good:
    private function getTaskUDFValueResult(event:ResultEvent):String
      _udfValue = event.result as String;
    private function getUdfValuePrj (taskId:String, udfCaption:String):String
      _udfValue = "Loading...";
      _udfWs.getTaskUDFValue (taskId,udfCaption);
      while (_udfValue == "Loading...")
      return _udfValue;

    There is no any ideas, or may be you don't understand me?

  • Dynamical Tree handling multiple requests

    Hi,
    I think I already explained well my need. I currently have an
    implementation of a tree control that is dynamic. So, when I click
    to open a node, it sends a request to server to ask for its
    children.
    Attached you have my tree code.
    And here is a sample feedback I have from server in XML:
    <response>
    <status>OK</status>
    <message/>
    <data>
    <item id="3" type="folder" label="Item 1.1"
    isBranch="true"/>
    <item id="4" type="folder" label="Item 1.2"
    isBranch="false"/>
    </data>
    </response>
    The problem is that if I the user clicks too fast to open two
    branches, only the last request is added. THe other request is
    lost, but its node keeps the down arrow. If I try to close it then,
    it crashes the app.
    My question is how do I make this code able to work with
    simultaneous requests? I already tried via AsyncToken without
    success. The main problem using tokens is how to pick the selected
    item then. =\
    Thanks in advance,
    Best regards,
    Guilherme Blanco

    Zoram wrote:
    So can u kindly advice me where should I use Servlets here in my application in order to overcome the problem.Dude, you need to study struts as well. There is an underlying servlet handling all the requests, and based on action name it decides which action class it needs to call. All this is done behind the scenes what you as a developer do is write your logic in the Action class (or may be call some services from it). So it would be easier for us, if you can share the code where you have written the logic as well your Action class code.

  • How are OAM custom authentication plugins used for concurrent requests

    Custom authentication plug-ins are loaded by Access Server.
    I want to understand how they are used or how they work when multiple concurrent request start pouring in.
    Thanks.

    The access server is a multi-threaded application. The "Fn" function of the plugin is executed in each of the thread of the access server.

  • How to handle multiple request in the servlet

    how to handle multiple request in the servlet...
    Example:
    java forum...
    i'm login in the java forum at this time 1000 members make login in this....how happended in servlet?
    if we use thread how to implement in servlet ?

    Serlets are already threaded. The application container instantiates the servlet, then uses this instance in a new thread for every use.
    This is the reason that you should use (almost) no instance variables in a Servlet, but rather that (almost) everything should be local to the method.

  • How to handle multiple requests to the same servlet at one time?

    Hi,
    I am new to Servlets. I have doubt regarding ... Handling multiple requests to a servlet at a time.
    If we send a single request to a servlet, as know that group of objects such as servlet, servletContext, servletConfig, request, response and etc are created in the server, And if 1000's of requests are sent to a same servlet at a time, and if server memory capacity is less, then 1000's of objects are created in a server which would be heavy burden to Server. How to handle the application and development in such situation?
    Kind regards,
    veerendra

    Hi veerendra reddy ,
    By default any web server can will have a thread pool to handle client req's.
    In your point also heavy burden to server you are telling that depends on this.
    we can configure this min & max size of this thread pool.
    by default it will be 0-1000 for tomcat server.
    I am not sure in which file this configuration will be.
    But I hope in server.xml or some xml file consists this info.
    If You what you can edit accordingly. to overcome your heavy burden to server.
    Thanks & Regards
    Nagendra

  • Taking in many concurrent requests via a single servlet

    Hi,
    My objective for this topic is to find a way to make my tomcat app able to handle as many as possible concurrent requests.
    My app spec is
    -servlet running on Tomcat 5.0
    My app is a mobile text messaging app that receives requests via a single servlet, called InboundRequest. This servlet will,
    1. Read the HTTP params in the request
    2. Decide to which other servlet classes it should forward to (RequestDispatcher)
    3. The recipient servlet will read the HTTP param, process it and outputs the data via OutboundResponse java class.
    So, my issue is,
    1. What factor decides the number of concurrent requests my InboundRequest servlet can handle? Is it my code or Tomcat itself or the server hardware
    2. Since I'm using Request Dispatcher forwarding, if say i have a request that takes 5 seconds to complete the its task (to output the result via OutboundResponse), will in inhibits/stops any other requests that comes in during that 5 seconds?
    I appreciate all expertise i can get.
    Regards,
    Mel.

    There is nothing to worry about that concurrent request handling as container will create one instance of your servlet and then for each client request it will spwan a single thread which will handel the client request.If u r implementing SingleThreadModel then onle one thread will be spwan and it will handle the requests one by one .So it will be slower .

  • Does a filter instance handle multiple requests?

    A web container creates a thread to handle each request so that a servlet instance handles multiple requests at the sime time. What about a filter instance? Does a filter instance also handles
    multiple requests? or it handles only one at a time

    Here's a quote from the Servlet spec (2.3):
    After deployment of the web application, and before a request causes the container
    to access a web resource, the container must locate the list of filters that must be
    applied to the web resource as described below. The container must ensure that it
    has instantiated a filter of the appropriate class for each filter in the list, and called its
    init(FilterConfig config) method..............
    Only one instance per filter declaration in the deployment descriptor is
    instantiated per Java virtual machine of the container.
    So, if the servlet engine follows the spec, there should only be one instance.

  • How biztalk handle multiple request at a time ?

    can TCP/IP adapter or biztalk handles multiple request at a time ?
    If yes,then how it process multiple request ? 
    Can TCP/IP send ports sends multiple request ?
    Prakash

    Yes.
    It processes multiple requests using THREADS. Each Connect starts off a thread that handles the receipt of the message, submission to BizTalk, wait for the response (matching two-way subscription) and then respond back to the client.
    TCP/IP Send ports handle multiple requests by creating fresh sockets (RPC High-end ports). As an example, in your browser you open multiple tabs and access different sites, each tab results in your browser opening a fresh socket connection for the request.
    Regards.

  • How to create/design a servcie request screen to handle multiple sets of request details ?

    Hi All,
    There is a business requirement to create a service request template to handle user account creation requests for a specific application. The inputs for this request is user name and email ID. The account creation requests are made by the dept managers. Most of the time the dept managers make multiple account creation requests at the same time.
    I have already created a service request screen that has "Username" and "Email ID" as input fields . But the problem with this design is for every single account a new service request need to be raised. 
    I want to redesign the service request screen so that it can handle multiple user account requests with a single service request. The number of users for each request varies.
    Is there a way to dynamicaly add multiple input field sets (User name and Email ID),  when creating a new service request ? or Is there any other way to achive this requirement ?
    Thanks.

    Could it be that those users you are asking permission for with this particular service request already exist in VSM system (as an example when VSM is integrated with AD)? If yes, then you can use custom Multiple Value QD [of the Person entity] to select required persons and add as many persons as you like to your request.
    Otherwise it may require deeper analysis of your business requirements. For now I have only some ideas to use Service Actions or custom javascript to create more advanced customer portal interface.
    In this case I would suggest to contact Alemba PSO for an extra service if possible.
    Regs, Gytis

  • Invoking multiple servlets from a single request

    Hi. I'm wondering if it's possible to execute multiple servlets within a single request and context. I have a servlet defined in web.xml which says:
    <servlet>
    <servlet-name>firstServlet</servlet-name>
    <servlet-class>mypackage.First</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>firstServlet</servlet-name>
    <url-pattern>/*</url-pattern>
    </servlet-mapping>
    (clearly this one gets invoked upon every request in the context)
    But I also have another servlet which gets invoked when another condition applies:
    <servlet>
    <servlet-name>secondServlet</servlet-name>
    <servlet-class>mypackage.Second</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>secondServlet</servlet-name>
    <url-pattern>*.ftl</url-pattern>
    </servlet-mapping>
    So if the url was http://localhost:8080/mycontext/page.ftl, I want both servlets to get executed. Is there anyway I can do this? I've tried the above code and it doesn't work. How would I do this (or can I even do it)?
    Thanks,
    Dylan

    depending on what your servlets do, you might also think of using filters. say you have a first servlet that compresses the respone you would be better off to implement this as a filter. than you might have a second serlvet that does request logging stuff. this might also be better than in a filter, so you chain first and second filter. the business logic is put in servlet three i.e.

  • How many Concurrent Requests handled in XI?

    Hi,
    Can anybody let me know how many concurrent requests can be handled in XI and where to check this number for a syncronous scenario ?
    Thanks
    Sreenivas

    Hi sreenivas,
    it depends mainly on the number of work process available in your system and on the tuning of java vm.
    Have a look at <a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/70ada5ef-0201-0010-1f8b-c935e444b0ad">SAP Exchange Infrastructure Tuning Guide XI 3.0</a>
    Hope it helps,
    best regards,
    Sergio

  • Can a servlet handle other than HTTP request..?

    I was asked this question in a interview. Can anyone clear me this.
    Can a servlet handle other than HTTP request..?
    If yes, please give me a working example.

    Can anyone guide me to achieve this.?
    Note: If anyone worked with servlet responding ftp request, please send me the code.
    Yes, a servlet can handle requests in other protocols
    like FTP.
    To achieve this, your Servlet ought to inherit from
    javax.servlet.GenericServlet or implement the
    javax.servlet.Servlet interface. To code the Servlet,
    you should have a working knowledge of ftp protocol.
    When your servlet extends
    javax.servlet.http.HttpServlet, it can process http
    requests only.
    Cheers,
    ram.

  • IISProxy can't handle concurrent requests

    Hi
    Im working with a cluster of 2 WLS5.1/SP8
    One IIS5 Running on Windows2000.
    I configured successfully iisforward and iisproxy and everything works fine
    as long as few users work with the system.
    however when trying to send a concurrent request from 20 users some of them
    up to 10 gets a 403 as response.
    I can see it in the IIS access log file as well.
    I turned debug=ON in the iisproxy.ini and i see that only the number of
    users that do get a 200 response are realy being sent to one of the WLS
    pair, those that return 403 seems not to even try to connect to a WLS.
    It seems like a weblogic bug.
    Help will be appreciated
    Dror.

    It seems that the problem is IIS on Win2000 Workstation has a 10 connection
    hardcoded limit
    "Dror Last" <[email protected]> wrote in message
    news:[email protected]..
    Hi
    Im working with a cluster of 2 WLS5.1/SP8
    One IIS5 Running on Windows2000.
    I configured successfully iisforward and iisproxy and everything worksfine
    as long as few users work with the system.
    however when trying to send a concurrent request from 20 users some ofthem
    up to 10 gets a 403 as response.
    I can see it in the IIS access log file as well.
    I turned debug=ON in the iisproxy.ini and i see that only the number of
    users that do get a 200 response are realy being sent to one of the WLS
    pair, those that return 403 seems not to even try to connect to a WLS.
    It seems like a weblogic bug.
    Help will be appreciated
    Dror.

  • Multiple POST requests

    Greetings everybody,
    For this particular question I am not getting any help from the Java forums and Google.
    Not very long ago I had to send a stream of bytes from an applet to a servlet (the applet and its helper classes are packed inside a signed jar file), but I used to fail miserably at every step.
    I tried every trick in the book (for me the books were Google and Java forums!!). I set the servlet's path in the Windows CLASSPATH, I tried to call the applet from within a servlet- of course after placing the applet file in the servlets folder- (in the hope that since the applet was in the same location as the servlets the URL would get established) e.t.c but still URL url=new URL(<servlet URL>) refused to invoke the servlet.
    Finally somehow I managed to get it done using the code below:
    public class Xyz extends Applet
    //DONT BE SURPRISED RIGHT NOW!!
    Class cls=this.getClass();
    ClassLoader cldr=cls.getClassLoader();
    //THE ACTUAL SERVLET CONNECTING CODE
    URL url=cldr.getResource("http://localhost:8000/servlet/<SomeServlet>");
    /*This statement does not work........ URL url=new URL("http://localhost:8000/servlet/<SomeServlet>").A NULL URL OBJECT GETS CREATED!! */
    HttpURLConnection hurlc=(HttpURLConnection)url.getConnection();
    //ALL THE NECESSARY FORMALITIES TO BE PERFORMED TO WRITE THE STREAM TO THE SERVLET
    hurlc.setDoInput(false);
    hurlc.setDoOutput(true);
    hurlc.setUseCaches(false);
    hurlc.setRequestMethod("POST");
    OutputStream os=hurlc.getOutputStream();
    //WRITING THE STREAM
    os.write(<some byte buffer>);
    //NOW COMES THE TRICKY PART
    hurlc.getResponseCode();
    I had to do getResponseCode() because once ClassLoader.getResource(<servlet URL>) invoked the servlet using the GET method I COULD NOT INVOKE THE SERVLET AGAIN. I had to force an invokation using getResponseCode().
    Well all is well now excepting for a small irritant. Instead of issuing one POST request the URLConnection is issuing multiple POST requests. In the Apache logs I get to see something like:
    GET /snodx/callapplet.htm 200 116
    GET /snodx/keystore_for_holding_fingerprint_for_trusted_applet 200 234
    GET /snodx/applet_and_helpers.jar 200 105
    HEAD /servlet/<SomeServlet> 200 187
    POST /servlet/<SomeServlet> 200 312
    POST /servlet/<SomeServlet> 500 604
    POST /servlet/<SomeServlet> 500 604
    The last 2 lines indicate that the servlet was invoked but the connection closed somehow. This is confirmed by taking a look at the Apache error logs:
    Premature end of script headers.
    Premature end of script headers.
    In the JServ servlet engine error logs I am getting:
    (500)apj12 returned an error handling request
    cannot scan servlet headers.
    The problem is occurring somewhere in getResponseCode().This statement is invoking the servlet using the request method set (POST) several times (2 or 3 times).
    Can someone explain what's going on?
    This is briefly the servlet code:
    public class SomeServlet extends HttpServlet
    //THE SERVICE METHOD IS CALLED BY A HEAD REQUEST TO THIS SERVLET
    public void service(ServletRequest reque,ServletResponse respon) throws ServletException,IOException
    this.doPost((HttpServletResponse)reque,(HttpServletResponse)respon);
    //GO DIRECTLY TO THE POST METHOD
    public void doPost(HttpServletRequest req,HttpServletResponse resp) throws ServletException,IOException
    ServletInputStream sis=req.getInputStream();
    if(sis.available()<2) //CHECK THAT THERE IS STREAM WHICH HAS AT LEAST 2 BYTES OF DATA!!
    log("NO STREAM FROM APPLET");
    else
    //PERFORM ALL ACTIONS TO WRITE TO STREAM OF BYTES TO A LOCAL FILE
    I have the servlet engine JServ 1.1.2 configured to run with Apache 1.3.19 on Windows 2000.
    I compiled the Applet and the Servlet using JDK1.3 and JSDK2.0. I have JRE 1.3.1_02 installed on my Win2k machine.
    Sorry for the long winded story here.
    Awaiting a reply.
    SNODX
    (The search keywords combination getResponseCode multiple POST requests +Applet and many other related keyword combinations did not match any document in the Java forums. The search string "Multiple POST requests" "getResponseCode" and many other related search strings did not match any document in Google.I am continuing the search effort however                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    interresting the classloader solution. Well if that works, i would keep it like that so far.
    But maybe this can help:
    os.write(<some byte buffer>);
    ..and then
    os.flush()//to make sure the outputstream is sent immediatly.
    //i think getResponseCode() is not necsessary in that case
    //but not certain, after all ...setUseCaches(false);
    One thing you should do is remove the complete
    service() {
    ...this.doPost();
    the reason is that when a POST arrives at the servlet, the default service-method of the ancestor class (which is javax.servlet.Servlet) will automaticaly make a call to doPost() of the javax.servlet.http.HttpServlet subclass. You should not overide it I believe.
    maybe... -try to establish an OutputStream only once in the Applet.
    - receive the other end exactly once (as you did) in the doPost as an InputStream;
    - eventually wrap both sides in respective Buffered(In)(Out)putStream(Reader)(Writer)
    - start looping and .write() and .read() at both sides on the single and same in-and-outputStream();
    (i.e avoid establishing the connection from the applet several times..., get one connection and keep it)
    sorry if this story would be irrelevant,
    Papyrus

Maybe you are looking for