Doubt on servlet architecture, URGENT

Hello Java experts!!
Please claurify my small doubt
In servlet architecture, if i write one servlet,
multi threading concept of servlets will be implemented in Servlet level or
doPost(doGet) level.
Because I wrote all functions out side the dopost method without synchronization.
And i am calling all the functions in side the dopost.
Will it handle multiple requests??
Regards,
SRAO

Yes it will handle multiple requests but you may have issues if two requests try to modify the same value at the same time. Servlets are not thread safe by default - it is up to you to deal with thread safety in the libraries your servlet is using, unless you use the single threaded servlet model by having your servlet implement the SingleThreadModel interface.
Sincerely,
Anthony Eden

Similar Messages

  • Question about servlet architecture

    Hello,
    I have a question about Web Application / servlet architecture and development, and haven't had any luck finding an answer so far. My plan must be either unusual, or wrong, or both, so I'm hoping the community here could point me in the right direction.
    I have quite a bit of background in OSGi, but very little in servlets. I know my architecture would work with something such as sever-side Equinox, but for the open source project I'm contemplating, I think that the more mainstream Tomcat/servler route would be better -- assuming it can be done. Here is a rather simplified scenario:
    There is a class, Manager. It could be a Java class that implements Runnable, or a non-HTTP servlet (GenericServlet?), but somehow it should be configured such that it runs as soon as Tomcat starts.
    When Manager runs, it instantiates its primary member variable: Hashtable msgHash; mshHash will map Strings (usernames) to ArrayList<String> (list of messages awaiting that user). Manager also has two primary public methods: addMsg() and getMsgs().
    The pseudocode for addMsg is:
    void addMsg(String username, String msg) {
    if username=="*" { for each msgList in msgHash { msgList.add(msg) } return;
    if username not in msgHash { msgHash.add(username, new ArrayList<String>) }
    msgHash[username].add(msg)
    And for getMsgs():
    String getMsgs(username) {
    String s = "";
    for each msg in msgHash[username] { s = s + msg; }
    return s;
    Once Manager has started, it starts two HTTP Servlets: Sender and Receiver, passing a reference back to itself as it creates the servlets.
    The HTML associated with Sender contains two text inputs (username and message) and a button (send). When the send button is pressed and data is POSTed to Sender, Sender takes it and calls Manager.addMsg(username.value, message.value);
    Receiver servlet is display only. It looks in the request for HTTP GET parameter "username". When the request comes in, Receiver calls Manager.getMsgs(username) and dumps the resulting string to the browser.
    In addition to starting servlets Sender and Receiver, the Manager object is also spawning other threads. For example, it might spawn a SystemResourceMonitor thread. This thread periodically wakes up, reads the available disk space and average CPU load, calls Manager.addMsg("*", diskAndLoadMsg), and goes back to sleep for a while.
    I've ignored the synchronization issues in this example, but during its lifecycle Manager should be idle until it has a task to do, using for example wait() and notify(). If ever addMsg() is called where the message string is "shutdown", Manager's main loop wakes up, and Manager shuts down the two servlets and any threads that it started. Manager itself may then quit, or remain resident, awaiting a command to turn things back on.
    Is any of this appropriate for servlets/Tomcat? Is there a way to do it as I outlined, or with minor tweaks? Or is this kind of application just not suited to servlets, and I should go with server-side Equinox OSGi?
    Thanks very much for any guidance!
    -Mike

    FrolfFla wrote:
    Hello,
    I have a question about Web Application / servlet architecture and development, and haven't had any luck finding an answer so far. My plan must be either unusual, or wrong, or both, so I'm hoping the community here could point me in the right direction.
    I have quite a bit of background in OSGi, but very little in servlets. I know my architecture would work with something such as sever-side Equinox, but for the open source project I'm contemplating, I think that the more mainstream Tomcat/servler route would be better -- assuming it can be done. Here is a rather simplified scenario:
    There is a class, Manager. It could be a Java class that implements Runnable, or a non-HTTP servlet (GenericServlet?), but somehow it should be configured such that it runs as soon as Tomcat starts.You can configure a servlet to be invoked as soon as Tomcat starts. Check the tomcat documentation for more information on that (the web.xml contains such servlets already though). From this servlet you can start your Manager.
    >
    When Manager runs, it instantiates its primary member variable: Hashtable msgHash; mshHash will map Strings (usernames) to ArrayList<String> (list of messages awaiting that user). Manager also has two primary public methods: addMsg() and getMsgs().
    The pseudocode for addMsg is:
    void addMsg(String username, String msg) {
    if username=="*" { for each msgList in msgHash { msgList.add(msg) } return;
    if username not in msgHash { msgHash.add(username, new ArrayList<String>) }
    msgHash[username].add(msg)
    And for getMsgs():
    String getMsgs(username) {
    String s = "";
    for each msg in msgHash[username] { s = s + msg; }
    return s;
    Once Manager has started, it starts two HTTP Servlets: Sender and Receiver, passing a reference back to itself as it creates the servlets. Not needed. You can simply create your two servlets and have them invoked through web calls, Tomcat is the only one that can manage servlets in any case. Servlets have a very short lifecycle - they stay in memory from the first time they are invoked, but the only time that they actually do something is when they are called through the webserver, generally as the result of somebody running the servlet through a webbrowser, either by navigating to it or by posting data to it from another webpage. The servlet call ends as soon as the request is completed.
    >
    The HTML associated with Sender contains two text inputs (username and message) and a button (send). When the send button is pressed and data is POSTed to Sender, Sender takes it and calls Manager.addMsg(username.value, message.value);
    Receiver servlet is display only. It looks in the request for HTTP GET parameter "username". When the request comes in, Receiver calls Manager.getMsgs(username) and dumps the resulting string to the browser.This states already that you are going to run the servlets through a browser. You run "Sender" by navigating to it in the browser. You run "Receiver" when you post your data to it. Manager has nothing to do with that.
    >
    In addition to starting servlets Sender and Receiver, the Manager object is also spawning other threads. For example, it might spawn a SystemResourceMonitor thread. This thread periodically wakes up, reads the available disk space and average CPU load, calls Manager.addMsg("*", diskAndLoadMsg), and goes back to sleep for a while.Since you want to periodically run the SystemResourceMonitor, it is better to use a Timer for that in stead of your own thread.
    >
    I've ignored the synchronization issues in this example, but during its lifecycle Manager should be idle until it has a task to do, using for example wait() and notify(). If ever addMsg() is called where the message string is "shutdown", Manager's main loop wakes up, and Manager shuts down the two servlets and any threads that it started. Manager itself may then quit, or remain resident, awaiting a command to turn things back on.
    Is any of this appropriate for servlets/Tomcat? Is there a way to do it as I outlined, or with minor tweaks? Or is this kind of application just not suited to servlets, and I should go with server-side Equinox OSGi?
    Thanks very much for any guidance!
    -MikeI don't see anything that cannot be done in a normal java web environment, as long as you are aware of how servlets operate.

  • Urgent-doubt in servlets

    hi to all,
    i am using tomcat server.i have a doubt in executing packaged servlet and it shows error 404 cannot resolve symbol when i tried to access thru browser
    i have attached below the mapping content of web.xml.Actually the servlet file got executed for packageless servlet and there is a
    problem in executing the packaged servlet.
    Any help would be highly appreciable because i have tried few methods
    and it didn't work out.help me
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd">
    <web-app>
    <display-name>Welcome to Tomcat</display-name>
    <description>
    Welcome to Tomcat
    </description>
    <* mapping content for packageless servlet */
    <servlet>
    <servlet-name>HelloServlet</servlet-name>
    <servlet-class>HelloServlet</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>HelloServlet</servlet-name>
    <url-pattern>/servlet/HelloServlet</url-pattern>
    </servlet-mapping>
    <* mapping content for packaged servlet */
    <servlet>
    <servlet-name>HelloServlet2</servlet-name>
    <servlet-class>moreservlets.HelloServlet2</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>HelloServlet2</servlet-name>
    <url-pattern>/HelloServlet2</url-pattern>
    </servlet-mapping>
    </web-app>
    reg,
    arv

    Hi aarvindk,
    I remember <servlet-mapping> tags must appear after any <servlet> tags in web-app document.

  • Doubt in ORA_FFI(Its urgent)

    Hi,
    I've created a test.dll which contains caps func as follows:
    int caps()
         int * ptr=0x417;
         if (*ptr==64)
              return 1;
    else
    return 0;
    Then I called this func through ORA_FFI package..
    DECLARE
    dll_handle ORA_FFI.LIBHANDLETYPE;
    winexec_handle ORA_FFI.FUNCHANDLETYPE;
    vn_ret PLS_INTEGER;
    FUNCTION Runp( handle IN ORA_FFI.FUNCHANDLETYPE)
    RETURN PLS_INTEGER;
    PRAGMA INTERFACE(C, Runp, 11265);
    BEGIN
    break;
    dll_handle := ORA_FFI.REGISTER_LIBRARY(NULL,'test.dll');
    winexec_handle := ORA_FFI.REGISTER_FUNCTION(dll_handle,'caps');
    ORA_FFI.REGISTER_RETURN(winexec_handle,ORA_FFI.C_INT);
    vn_ret := Runp(winexec_handle);
    IF vn_ret = 2 THEN
    MESSAGE('Cannot find file ' );
    END IF;
    EXCEPTION WHEN OTHERS THEN
    FOR i IN 1..Tool_Err.NErrors LOOP
    message(Tool_Err.Message);
    Tool_Err.Pop;
    END LOOP;
    END;
    When I debug this code,It gives error as caps func not found in test.dll.
    But the only func in test.dll is caps..
    I'm using forms 6i in client server mode.
    I created test.dll using Microsoft visual c++ by creating new win32 Dynamic link library.
    One more doubt:
    How can I find functions in a already compiled DLL?
    Pls reply me..Its urgent..
    Adios..
    Prashanth Deshmukh

    Hi,
    refer these ,u will get some help
    Standard Buttons:
    https://www.sdn.sap.com/irj/sdn/wiki?path=/display/snippets/webDynproABAP-ALVControllingStandard+Buttons&
    alv-pfstatus:
    http://www.sapdevelopment.co.uk/reporting/alv/alvgrid_pfstatus.htm
    then how to capture that button click.
    http://www.sapdevelopment.co.uk/reporting/alv/alvgrid_ucomm.htm
    http://www.sapdevelopment.co.uk/reporting/alv/alvgrid_rowsel.htm

  • Can i use Web Start for applet servlet architecture

    Hello ,
    I am currently working on conversion of swings GUI to applet based so that it can be accessed any where from the network.
    Presently its a standalone application, requiring installation of the work station component on user's machine .This would access the database on other server using the JDBC ODBC drivers.The GUI would display the information from the database.
    The task is to make it accesible remotely using a webbrowser.I have thought of the following.
    1.
    Applet-->Servlet--->Database architecture
    I was wondering if i can do the same functionality with Webstart. I mean will i be able to deploy the present application and make connections to the host server.
    Please compare the options .

    No , this is not supported by Oracle.
    Regards Anders Northeved

  • Applet Servlet communication (urgent)

    Hi,
    I m using Netscape Enterrpise server 4.0 as my web server. I am passing data from applet to servlet using BufferedInputStream(). But it takes about 30 seconds to send the data. If i don't use it, the data is not being read by the servlet. Is there any alternative to this ? Please help.
    Thanks

    It's only the primary key field that i am passing to the servlet from applet .. For this particular process, it takes 30 seconds + other things like loading the applet, etc. so in all, it takes about 1 minute just to fetch the data from servlet which is not reasonable. We have monitored the whole process. We found that other things like query, etc. does not take much time, but BufferedInputStream() itself takes 30 seconds. Regarding communication line, it is quite fast. We are a corporate sector, so no doubt about the speed of the communication line ...
    Thanks for help.

  • Delete data dynamically with JSP and servlet (Very Urgent)

    Hi,
    I am new with servlets and JSP. On my jsp page I am populating customer names in a drop box from database and I have 3 buttons ADD, DELETE and EDIT.
    Now when I press DELETE buttong I am calling delete function which is writen in Javascript on my jsp file only,now I want to pass these selcted values ehich I have stored in an array to be pass to servlet,so I can write Delete query for it and delete.
    Could anyone help with sample code>
    Here what I am trying to say:
    <HTML>
    <HEAD>
    <script language="JavaScript" type="text/javascript">
    <!--
    function remove()
    var u = confirm("Are you sure you want to Delete Selected names?")
    if (u==true)
         var selectedArray = new Array();
         var selObj = document.getElementById('CUSTOMER_NAME');
         var i;
         var count = 0;
         for (i=0; i<selObj.options.length; i++) {
         if (selObj.options.selected) {
         selectedArray[count] = selObj.options[i].value;
         count++;
         alert("names to be deleted are:"+selectedArray);
         // selectedArray has the selected items stored
         alert("Items Deleted!")
    else
    alert("No data were deleted!!You pressed Cancel!")
    //-->
    </script>
    </HEAD>
    <BODY>
    //calling servlet on action tag of form
    <FORM METHOD= 'POST' ACTION='Remove_Customer'>
    <form ><INPUT TYPE='submit' NAME='DELETE' VALUE='DELETE' onclick="remove()"></TD></form>
    <form><INPUT TYPE='submit' NAME='MODIFY' VALUE='MODIFY' onclick="modification()" ></TD></form>
    </BODY>
    </HTML>
    PLEASE HELPME,it's very urgent.
    Since the selected Array is in javascrip language , I don't know how can I pass that to servlet.
    request.getParameter is not working,since it's an array
    Many thanks in Advance.

    Hey,
    I am having problem deleting multiple values.
    If I just select one value,it deletes it
    But for multiple values the code is not working right.
    If there 2 values selcted then the last value gets deleted,if there are more than 2 values selected none values delete.
    Could plese check the code,and let meknow what mistake am I doing?
    Please help
    String delName="";
    int pos = tStr.indexOf(",");
    System.out.println(pos);
         if (pos != -1)
                   delName = tStr.substring(0, tStr.indexOf(","));
              tStr = tStr.substring(tStr.indexOf(",") + 1 );
                   System.out.println("DElName:"+delName);
                   System.out.println("tStr::"+tStr);                              
                        delName = tStr;
                        delete_Customer(delName);
    Thanks
    ASH

  • Request.getParameter() values in servlet? Urgent

    String str=request.getParameter();
    I am facing a problem when i submit the arabic values from hidden form fields using javascript.
    In servlet when i tries to retrive the arabic values stored in the session, it displays only
    garbage values(ie. ?????????).
    How to solve this problem?
    Please clarify and if possible give some samples.
    Thanks & Regards,
    Govindaraman

    Hi Govindaraman,
    in O'Reilly's Servlet book in the internationalization section it describes how. You have to change the String returned into bytes using the proper enconding, then back into a String to it will convert to Unicode.
    The basics are this:
    String parameterName="your param name";
    String encoding = "your charset encoding on the page";
    String value = request.getParameter(parameterName);
    value = new String(value.getBytes(), encoding);
    value is now a Unicode string that should be correctly interpreted.
    You can use new String( oldString.getBytes(), encoding) to convert between charsets.

  • Can't be able to connect mobile and the servlet ?(Urgent)

    hi to all java Gurus..
    I need ur help ..
    My problem is that I am not be able to connect my mobile Nokia N70 to the servlet and when I am trying with Emulator its working fine but having problem only with physical device.
    On that I have to connect to internet through GPRS.
    When I gave a call to the servlet during that time I wrote a string value in the output stream which is transferred as a piece of information according to which servlet respond.
    So plz tell me how to resolve this problem ??? frm the past one week I am stuck in this problem. plz help
    --- regards
    pank_naini
    Edited by: pank_naini on Jul 4, 2008 3:36 AM

    hi Omar,
    thnx.. but i clear the first part.. nw i am able to connect my application through phone and i m getting expected outcome but in my view there are some limitation when i gave a call (may be i would be wrong)
    - Application always run on the port 8080; earlier i was trying to connect on port 9080.
    - and method should be the GET rather then POST.
    if any one is wrong then i am not able to connect my application...
    Is there any setting in the phones ?
    --Regards
    pank_naini

  • 2-tier Client/server Architecture(Urgent!!!!)

    Hi,anyone can help me to do a client/server architecture.The server is able to track and store the client's name,IC number and his machine's IP.And the server is able to broadcast a question stored in the database and get the answer to the question whereby the answer is also stored in the database.The server is able to broadcast the question to multiple server.Thanks!

    Hi,anyone can help me to do a client/server
    architecture.The server is able to track and store the
    client's name,IC number and his machine's IP.And the
    server is able to broadcast a question stored in the
    database and get the answer to the question whereby
    the answer is also stored in the database.The server
    is able to broadcast the question to multiple
    server.Thanks!you mean able to broadcast to multiple clients, right?
    read this webpage:
    http://java.sun.com/docs/books/tutorial/networking/sockets/clientServer.html
    steal some of the code... maybe from the knock knock server client code and then modify it to meet your needs.
    Don't worry about storing the information in a database until after you have everything else working. The database stuff will require knowledge of JDBC.
    Good luck,
    Tim

  • How ODI works? Doubt in basic Architecture.

    Hi,
    I need to know how ODI (Architecture) works on basic transformations. From my understanding,
    1) ODI extracts the data from source, create some temp tables in Staging Area and put the data in temp table.
    2) From that temp table it puts the data to target and drop the temp table.
    is the two statements are correct? one more thing is that i am confident on 3rd point, please say wether its right.
    3) We can make all the temp tables to be created in a different database without affecting the target database (Using the option"Staging area diff from target")
    Any suggestions would really help.
    Thanks in Advance,
    Ram Mohan T

    Hi,
    Thanks a lot for your reply. I need no temporary tables should be created in target database. For that, i have taken
    Source and target from different databases and staging area as different database (in total three database for source, target and staging area).
    I used these knowledge modules - LKM Sql to Sql, IKM Oracle Incremental update, CKM oracle.
    When i execute the interface, two tables are created in target database (SNP_Check_tab, E$_emp_table), how can i avoid that.
    Any suggestions would really help.
    Thanks in Advance,
    Ram Mohan T.

  • Servlet Configuration - urgent

    I installed
    jdk-6u21-windows-i586.exe
    in my machine (xp s3) and I can run java progrms
    Now I want to know the following things
    1. Which version of jdk is this
    2. I want to run Servlets from my machine
    what additional software to install for this
    in which folder, how to configure?
    kindly give me step by step procedure for this, thanks in advance

    jdk-6u21-windows-i586.exe
    1. Which version of jdk is this1.6.21
    2. I want to run Servlets from my machine
    what additional software to install for thisApache Tomcat for example, Jetty: many other possibilities.
    in which folder, how to configure?Read the documentation for whatever you choose.
    kindly give me step by step procedureThis is a 'New to Java' Programming forum, not a help desk.

  • URLs with a JSP-servlet architecture

    I on of my webapp, there is a servlet that forward the request to a JSP. Please tell me why
    <form name="theForm" method="GET" action="thPackage.TheClass">works while:
    <form name="theForm" method="POST" action="thPackage.TheClass">dont. ???

    Could it be because of the you have specified only <http-method>GET</http-method>
    but not <http-method>POST</http-method> in the web deployment descriptor web.xml ?

  • Need iFS http-client/http-servlet architectural advice.

    I need to design a custom client to connect to an iFS http protocol server in order to allow users of my client to drop document objects (files) on iFS and modify properties (metadata) of those document objects.
    In other words, my client connects to iFS via http, and lets the user upload "files" to iFS, but more importantly, also lets the user enter values for custom properties associated with the class objects corresponding to the iFS document objects being uploaded.
    Fo a while, WebDAV looked like a good solution. But I just discovered WebDAV does not allow me to access custom properties for an iFS object.
    It looks to me now that my only alternative is to also write a custom servlet and have my custom client connect to that servlet. This is not desireable from a product viewpoint since it requires special installation at the server.
    My custom client is to be integrated in an already existing application that manages files, so I really need to write my own special client. I cannot use the WebUI.
    Any idea, tips, or advice from the iFS gurus would be greatly appreciated.
    Is there any way to avoid the custom servlet approach. For instance, is there some existing agent or servlet that I can just send XML requests to ?

    What version are you running?
    If 9iFS v9.0.2 or prior you may be able to achieve what you are after by use of XML files that would update metadata of an existing 9iFS object.
    CM SDK v9.0.3 and later only supports parsing of XML from the CUP protocol - so you would be out of luck here.
    Your best bet it to write the custom servlet unfortunately.
    There is an enhancement filed for the CM SDK WebDAV servlet to allow hooks that will enable you to do your own processing throughout the transaction.
    Matt.

  • Can one form submit to different servlets? Urgent!!!!

              Hi, all
              Can someone tell me how can I submit one form to two servlets?
              The case is:
              Some of data in one form need to pass to one servlet, and the rest of them need
              to pass to another servlet. E.g. an Order form in some site, the financial info
              will go to some secure SSL credit card payment gateway, the product and delivery
              infor will goto another servlet. How do u handle the case? Does anyone know?
              Thanx in advance
              Divid
              

    This sounds like a candidate for a controlling servlet that handles a single
              request, then forwards 'pieces' of each request to different servlets.
              Hope this helps
              Rob
              "JFan" <> wrote in message news:3b789f4c$[email protected]..
              >
              > Hi, all
              >
              > Can someone tell me how can I submit one form to two servlets?
              > The case is:
              > Some of data in one form need to pass to one servlet, and the rest of them
              need
              > to pass to another servlet. E.g. an Order form in some site, the financial
              info
              > will go to some secure SSL credit card payment gateway, the product and
              delivery
              > infor will goto another servlet. How do u handle the case? Does anyone
              know?
              >
              > Thanx in advance
              >
              > Divid
              

Maybe you are looking for

  • JSF error handling when the bean is not correctly loaded

    Hi, I am doing some error handling in JSF and I want to do it in an elegant way. I have the following scenario for error handling. When the bean is initialized I load the bean with values from DAO which give SQL Exceptions. Since the bean is not load

  • BW Business Content

    Does anyone have the complete BW business content as a pdf or word. document.

  • J2ee tutorial. "ant create-tables" problem

    I am following Java ee 5 tutorial. In one of its sections it asks me to populate the db by following the below instructions: 1. In a terminal window, go to the books directory or any one of the bookstore1 through bookstore6 example directories. 2. St

  • How to identify low volume/level audio segments in a recording?

    Iam newbie to Audition and trying to edit/master a 2 hour long lecture done in a live setting (not studio). Since the speaker sometimes moves away from the microphone the level of the audio sometimes falls off or reduces sometimes for a few seconds t

  • Firefox 3.6.22 - Where to download this older version?

    I need to test an application using Firefox 3.6.22 on Windows. Can you please advise where I can safely download this version? Thanks.