Multiple Servlet Threads - per HttpSession

          Can there be concurrent Servlet threads on a single HttpSession in cases where
          there are multiple frames on the Browser Window, or if the user has multiple Windows
          open in the same Browser session? Or is it the case that the multiple requests
          on that HttpSession are synchronized to be done in sequence (WebLogic 6.1 as Web
          Server).
          If there can be concurrent threads then how are non-repeatable reads handled for
          objects stored in the HttpSession. For example two threads pick up object A from
          HttpSession, and overwrite each other changes when they set them back in HttpSession.
          Thanks,
          Pradeep
          

          Thanks but how does that protect against non-repeatable reads?
          Even if there is a synchronized session object in HttpSession still nothing to
          stop from concurrent threads from overwriting each other's settings if the threads
          picked up a value from session object, did some processing and wrote it back.
          (This is almost an optimistic concurrency type scenario)?
          Pradeep
          Alexander Petrushko <[email protected]> wrote:
          >Pradeep Behl wrote:
          >
          >> Can there be concurrent Servlet threads on a single HttpSession in
          >cases where
          >> there are multiple frames on the Browser Window, or if the user has
          >multiple Windows
          >> open in the same Browser session? Or is it the case that the multiple
          >requests
          >> on that HttpSession are synchronized to be done in sequence (WebLogic
          >6.1 as Web
          >> Server).
          >>
          >> If there can be concurrent threads then how are non-repeatable reads
          >handled for
          >> objects stored in the HttpSession. For example two threads pick up
          >object A from
          >> HttpSession, and overwrite each other changes when they set them back
          >in HttpSession.
          >
          >It's up to the application to prevent the threads from stepping on each
          >other when it
          >comes to HttpSession. You can create a thread-safe session class, store
          >your session
          >objects in the instance of that and then have HttpSession store the thread-safe
          >impl.
          >
          >Cheers,
          >
          >Alex
          >
          >
          

Similar Messages

  • Forums multiple threads per topic

    Is it possible to have multiple threads per forum topic?

    Hi Mounia, I don't believe there's a way to do this out of the box. My suggestion would be to create a discussion board for each topic or use a third party solution. I haven't used this particular one, but can vouch for the company's products:
    http://www.kwizcom.com/sharepoint-add-ons/sharepoint-discussion-board-feature/overview/
    cameron rautmann

  • Servlet Thread Pools for iPlanet WS 4.1

    We have iPlanet WS 4.1 SP 5, running on HP UX. Wanted to make sure servlets run fast, so set up servlet thread pool. Initial result was that even the startup servlet could not be loaded, got stack overflow. Reduced number of threads from 60 to 5. Now startup servlet kicked off OK, but a subsequent servlet processing a request bombed with same error. This is obviously some kind of resource issue; how does one allocate enough memory or whatever it needs to handle the thread pool? Do I really even need a thread pool?

    Thanks, and a follow-up question: at that reference, it seemed to imply there is really no need to allocate a user thread pool if running on Unix. Could even slow down the application. Am I likely to be OK with about 300 concurrent users if I don't allocate a thread pool? I was afraid they'd be single-threaded through the front controller servlet if I did not specifically allocate and use a thread pool, but perhaps multiple threads are already built into the container?

  • Is Servlet thread safe?

    Hi,
    I have created a application. All that the application does is that it listens at a predefined port say 8080 and for every request that is made to the application, the request header information is dumped into a file.
    I have implemented it by creating a servlet that implements the Filter interface and implemented its doFilter() method.
    In the method, I simply make use of the Servlet Request object and wite the header details in a file.
    The question : Is the above written Servlet class - thread safe?
    There are no class member variables defined.
    I have deployed the application on Tomcat 5.0.19.
    Regards,
    Montek Singh Ahluwalia

    Yes, Servlets are thread safe.
    Although it is standard to have one servlet instance per registered servlet name, it is possible for a servlet to elect instead to have a pool of instances created for each of its names, all sharing the duty of handling requests. Such servlets indicate this desire by implementing the javax.servlet.SingleThreadModel interface. This is an empty, tag interface that defines no methods or variables and serves only to flag the servlet as wanting the alternate life cycle.

  • Multiple servlets vs parameterized service

    I'd appreciate any advice/reccomendations anyone has on this topic
    What are the trade offs in the following scenario where I have a set of related use cases I want my web app to handle. Is it best to have a servlet per use case (eg in a web store, I might have "buy item", "list products", "view cart") or is it best to have a single servlet and have that distinguish the particular use case from the URL/input parameters.
    What are the overheads of multiple servlet objects in this scenario esp where as in the exampe above a "buy item" would affect the results of "view cart"
    I realise I can use struts or similar to achieve the described effect, I'm more interested in the technical factors behind the choice above
    thanks

    its better if u can have only 1 servlet for alll the use case.it can be your Controller and this is called MVC arch. If u use seperate servlet for each use case then u have to repeat generic code in each servlet and u also be writing the business in the servlet thats worng. u should write all the business in seperate class which may be reused and this is called model in MVC.if u use single servlet it may become long but u can seperate in 2 or more but not each servlet for each use case.

  • How to use my connection pool in multiple servlets?

    I now have a functioning connection pool using these lines in a servlet:
    private Connection getConnection(String lookup) throws NamingException, SQLException {
    Context context = new InitialContext();
    DataSource ds = (DataSource)context.lookup(lookup);
    Connection ocon = ds.getConnection();
    context.close();
    return ocon;
    } // private Connection getConnection(String lookup) throws NamingException, SQLException {
    ========================
    If I want to create additional servlets in the same web app which query the same database,
    do I need to repeat this block of code in every servlet, or can I just put it in one servlet
    and have other servlets access it in some way to get a connection? Should I change the code
    above from a "private" Connection to a "public" Connection?
    An example servlet is shown below. To put my question another way: If I want to
    create a second servlet with a different set of queries, would I just make a copy of the first
    servlet and then change only the queries, or is there a more efficient way to have multiple
    servlets get connections from the pool?
    Any suggestions are greatly appreciated.
    Thank you.
    Logan
    ************************************servlet example**********************************
    package CraigsClasses;
    import javax.servlet.*;
    import javax.servlet.jsp.*;
    import java.net.*;
    import java.util.*;
    import java.io.*;
    import javax.servlet.http.*;
    import java.sql.*;
    import java.util.Date;
    import java.text.*;
    import javax.naming.*;
    import javax.sql.DataSource;
    public class CraigsMain extends HttpServlet {
    public void init(ServletConfig config) throws ServletException {
    super.init(config);
    private Connection getConnection(String lookup) throws NamingException, SQLException {
    Context context = new InitialContext();
    DataSource ds = (DataSource)context.lookup(lookup);
    Connection ocon = ds.getConnection();
    context.close();
    return ocon;
    } // private Connection getConnection(String lookup) throws NamingException, SQLException {
    // Process the http Get request
    public void doGet(HttpServletRequest request, HttpServletResponse response)
         throws ServletException, IOException {
    try {
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    String sql = "select formtitle from checkboxforms where cbformid = 157";
    // error occurs at this line
    Connection ocon = getConnection("java:comp/env/jdbc/CraigsList");
    PreparedStatement pStmt = ocon.prepareStatement(sql);
    ResultSet rs1 = pStmt.executeQuery();
    rs1.next();
    out.println("<br>" + rs1.getString(1));
    rs1.close();
    pStmt.close();
    ocon.close();
    } catch(SQLException sqle) {
    System.err.println("sql exception error: " + sqle);
    } catch(NamingException ne) {
    System.err.println("naming exception error: " + ne);
    public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    doGet(request, response);
    =======================================================================

    sjasja, Thank you for the reply. What you are suggesting is exactly what I have been looking for. But I'm pretty weak on how to make this separate con pool servlet work. My first attempt is shown below. It doesn't compile this line, which is obviously wrong:
    public static Connection getConnection(String lookup) throws NamingException, SQLException {
    Could you please help me with this servlet code? Thanks.
    package CraigsClasses;
    import javax.servlet.*;
    import javax.servlet.jsp.*;
    import java.net.*;
    import java.io.*;
    import javax.servlet.http.*;
    import java.sql.*;
    import javax.naming.*;
    import javax.sql.DataSource;
    public class ConPoolInit extends HttpServlet {
    public void init(ServletConfig config) throws ServletException {
    super.init(config);
    try {
    public static Connection getConnection(String lookup) throws NamingException, SQLException {
    Context context = new InitialContext();
    DataSource ds = (DataSource)context.lookup(lookup);
    Connection ocon = ds.getConnection();
    context.close();
    return ocon;
    } // private Connection getConnection(String lookup) throws NamingException, SQLException {
    } catch(SQLException sqle) {
    System.err.println("sql exception error: " + sqle);
    } catch(NamingException ne) {
    System.err.println("naming exception error: " + ne);
    =======================================

  • How to configure multiple smtp servers per domain

    Hi,
    how do we configure multiple smtp servers per domain/corporate in iplanet messaging server 5.2. i wanted to do this so that i can configure some domains with virus scanning and some domains without antivirus.

    Hi Martin,
    Well we are trying to run a report without exactly specifying the name of reports server anywhere, e.g. in database or in form or anywhere else. Now if I do not supply a reports server name using RUN_REPORT_OBJECT, the error it displays is FRM-41211: Integration Error : SSL failure ... However if I specify the reports server name in the form, the reports run perfect. Also the name of reports server is specified in rwservlet.properties.
    Now the question goes as follows:
    Can I run my report from Form without specifying the name of the Reports server anywhere at all. This is so because either an in-process reports server should be picked or the one which is entered in rwservlet.properties should be pickec up by default. Please correct us if we are wrong. once we are through with it, we have to move to Oracle 10gR2 concept of reports server.
    Thanks in anticipation,
    Ruchi/Saurabh

  • Problem with running multiple servlet in same webapplication with tomcat 3

    Hi all,
    I am using Tomcat 3.0 as webserver with jdk1.3, Servlet 2.0,
    Templates for html file and oracle 8i on UNIX platform.
    I have problem with multiple servlet running same webapplication.
    There are two servlet used in my application. 1) GenServlet.class
                   and 2) ServletForPrinting.class
    All of my pages go through GenServlet.class which reads some property files
    and add header and footer in all pages.
    I want reports without header & footer that is not possible through GenServlet in my application.
    So I have used another servlet called ServletForPrinting --- just for reading html file.
    It is as follow:
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class ServletForPrinting extends HttpServlet {
    public void service (HttpServletRequest request,
    HttpServletResponse response) throws ServletException, IOException
    // set content-type header before accessing the Writer
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    File f1 = null;
    String report = null;
    String path = request.getPathInfo();
    try{
    String p = "/var/home/latif/proj/webapps/WEB-INF/classes" + path;
    System.out.println(p);
    f1 = new File(p);
    p = null;
    if (f1.exists()) {
    FileReader fr = new FileReader(f1);
    BufferedReader br = new BufferedReader(fr);
    report = new String();
    while ((report = br.readLine()) != null) {
    out.println(report);
    }catch(Exception e) {
    out.close();
    report = null;
    path = null;
    f1 = null;
    } // end class
    It works fine and display report properly.
    But now Problem is that if report is refreshed many times subsequently,
    WebServer will not take any new change in any of java file used in web-application.
    It works with the previous class only and not with updated one.
    Then I need to touch it. As soon as I touch it, webserver will take updated class file.
    Anybody has any idea regarding these situation?
    Is there any bug in my ServletForPrinting.java ?
    Any solution ????? Please suggest me.
    Suggestion from all are invited. That will help me a lot.
    Thanks in advance
    Deepalee.

    Llisas wrote:
    I solved the problem, I just had to wire the blocks in a sequential way (I still don't know why, but it works).
    Feel free to delete this topic.
    I would strongly suggest at least reading this tutorial to give you an idea of why your fix worked (or maybe only appeared to work).  Myself, I never just throw up my hands and say, "Whatever," and wash my hands of the situation without trying my best to understand just what fixed it.  Guranteed you'll run into the same/similar problem and this time your fix won't work.
    Please do yourself a favor and try to understand why it is working now, and save yourself (or more likely, the next poor dev to work on this project) some heartache.
    Bill
    (Mid-Level minion.)
    My support system ensures that I don't look totally incompetent.
    Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.

  • Multiple message threads from same person

    I have multiple message threads from the same person in messages on my iPhone and iPad. One comes from their phone number and one from their email. Here are all the details, I would love to be able to combine them into one thread.
    This other person and myself each have a new MacBook Pro, iPad Air 2, I have an iPhone 6 and they have an iPhone 5S. They are all updated with the most recent system software.
    On my MacBook Pro, the conversations that are split on my iPhone and iPad are not split. On the MacBook Pro, all of the texts from both conversations are appearing in one. In my contacts which are syncing with iCloud I have both the phone number and email address of this other person.
    I have messages set up on all of my devices to send and receive from my phone number and my email, start new conversations is from my phone number. This other person has it set up the exact same way on all of their devices.
    So why when I text this person from one conversation thread and they respond it comes through to the other conversation thread?
    Why can't I seem to join these two conversations when everything is set up the way it should be and they ARE joined on my MacBook Pro but not my iPhone and iPad?

    She kept the same number on her new phone, but now there are 2 conversation threads. A new one started with messages sent from the new phone, the old phone should be out of service now. Why didn''t  messages sent by the new phone resume in the same conversation? I assume because it's a different IMEI.  But now whenever I use her  phone number to create a new message, it goes in the old IMEI*'s conversation thread and is therefore not delivered. It's in green so it thinks it's an SMS also not a iMessage device.
    If I want to send a message correctly  to the new phone, I have to make sure I  go into the correct newer thread and enter it there,
    For your second answer, the person is receiving the message but the thread now says "email address", not the person's name in the contact list. The sender is sending to the person's phone number, not her email address.

  • Kernel parameters -maximum threads per process

    How can we change the kernel parameters also how can we increase the maximum number of threads allowed .
    How can we increase maimum perocess per used id .

    There is no kernel parameter limiting the maximum
    number of threads allowed. If you are talking about
    user level threads, you will run into virtual address
    space limitations at about 3000 for a process
    assuming 32-bit address space and default
    stack size of 1M per thread, and assuming you are
    not using the alternate thread library (see threads(3thr))
    or Solaris 9. If you need more than this many
    threads at the same time, I suspect you are doing something
    incorrectly. Otherwise, try using a smaller stack size
    per thread. If you are running on Solaris 9, or using
    the alternate thread library, both give you a 1x1
    thread model, i.e., each user thread has a corresponding
    kernel entity (lwp). In this case, you will cause
    your machine to hang by eating up all available
    space for lwp's. In either case, the question should be:
    "how do I limit the number of threads per process?", since
    there is currently no limitation other than space.
    In Solaris 9, you can use resource management to
    limit the number of lwp's (and therefore user threads)
    per process.

  • Max Number of threads per Process in Solaris 8

    I'm running into qpplication which crashes with a segfault when the LWP for that process hits about 255, i'm trying to find the maximum number of threads per process using sysconf and its returning -1
    #include <unistd.h>
    int
    main(void)
    printf("%ld\n",sysconf(_SC_THREAD_THREADS_MAX));
    return 0;
    I'm using gcc 3.3.2
    If anyone can tell me the maximum number of threads per process I would really appreicate it.
    Also the maximum number of open files per process.
    Thanks in advance
    - Rodrick Brown
    - DoITT

    Please make sure that you build a
    multithreaded program first (check with ldd).
    If anyone can tell me the maximum number of threads per process I would
    really appreicate it.
    Also the maximum number of open files per process. It depends on the architecture (x86/SPARC), OS version,
    64 or 32-bit, /etc/system, shell limitations (/usr/bin/ulimit) ...
    Search for "rlim_fd_max / rlim_fd_cur" on docs.sun.com too.
    HTH,
    -vladimir

  • Servlet thread pool

    Is there any way I can create my own init() for the threads in the servlet thread pool (by overriding some method or through other means)? (Not to be confused with the servlet's init().)

    web server itself is a thread pool implementation, unlesss your thread has other purpose, if not it is suited and enough for you do not implement another thread for it. If you want some init method, you can call from other class before start of your thread pooling.
    Hopefully can help you...

  • Adding multiple servlets under same application

    Hi,
    We are trying to add multiple servlets (2 to be precise) to an Application.
    We are using j2ee1.3 server and deploytool for deploying the same.
    Is it possible to have a single context root in which i'll be able to place both servlets with different aliases to access them?
    The moment I specify same contextRoot in Web context tab of Application, i get an error saying Deployment failed because "mycontextroot" already exists.
    When I assign two different context roots to each servlet, they can function, but then the URL for each changes inspite of being in the same application.
    Any suggestions are welcomed.
    Thank you,
    Manish.

    Hi,
    I did not quite follow the solution and I am wondering if it will solve a problem I am having.
    I wish to define multple jax-rpc endpoints, but I want the classes servicing those endpoints to be able to communicate with one another. I tried placing them both in the same war and entering two endpoints in the jaxrpc-ri.xml file, but it didn't like the second endpoint entry being there.
    Is there a way to do this?

  • Are servlets thread safe??

    Are servlets thread safe?? if not, then how to make them thread safe.

    Hi,
    servlets aren't thread-safe; you can make them thread-safe by implementing the interface javax.servlet.SingleThreadModel
    From the javadoc:
    public interface SingleThreadModel
    Ensures that servlets handle only one request at a time. This interface has no methods.
    If a servlet implements this interface, you are guaranteed that no two threads will execute concurrently in the servlet's service method. The servlet container can make this guarantee by synchronizing access to a single instance of the servlet, or by maintaining a pool of servlet instances and dispatching each new request to a free servlet.
    If a servlet implements this interface, the servlet will be thread safe. However, this interface does not prevent synchronization problems that result from servlets accessing shared resources such as static class variables or classes outside the scope of the servlet.

  • Calling pl/sql api through multiple java threads

    Hi All,
    I need to call a pl/sql api from multiple java threads simultaneously and all thread will use same db connection.
    I want to know if all the threads will simultaneously call the pl/sql api then will the local variable inside pl/sql procedure be shared between them or they will get separate instances of variables.
    TIA

    You cannot make multiple parallel client calls over the same Oracle session handle. There is a single non-threaded/non-fibre serialised server process servicing client requests for that session. (physical process on Linux/Unix, thread in the oracle.exe process on Windows).
    Each thread on the client side, needs its very own Oracle session. Thus each thread will have a server process footprint on the server. Which could be problematic if 10 clients each starts 10 threads - as it means a 100 processes on the server are needed to service these client threads.
    Have a look at Overview of OCI Multithreaded Development in the Oracle® Call Interface Programmer's Guide for how to use the threading call interface of the OCI - as oppose to rolling your own where each thread manually needs to deal with is OCI session context.

Maybe you are looking for