java servlet conflict

Discussion in 'Java' started by Steven S, Aug 3, 2003.

  1. Steven S

    Steven S Guest

    I have a servlet setup to access my database. The servlet works perfectly
    except when there are multiple simultaneous posts that run the servlet.

    It seems that that when the servlet is run by two separate threads they
    conflict somehow and cause the other to not function properly.

    The question is, how do I make sure each thread that is running concurrently
    runs without affecting the other threads?

    I tried setting the servlet as Private but got a compile error.

    Steve
    Steven S, Aug 3, 2003
    #1
    1. Advertising

  2. Steven S

    Steven S Guest


    > Probably the easiest fix is to have your servlet implement
    > SingleThreadModel which will force your engine to deploy an additional
    > instance of your servlet rather than trying to have one instance process
    > both requests concurrently.
    >
    > DM


    Could you elaborate a bit on how to do this?

    Thanks for the response,

    Steve
    Steven S, Aug 3, 2003
    #2
    1. Advertising

  3. Steven S

    VisionSet Guest

    "Steven S" <> wrote in message
    news:bgjju3$p5j4o$-berlin.de...
    > I have a servlet setup to access my database. The servlet works perfectly
    > except when there are multiple simultaneous posts that run the servlet.
    >
    > It seems that that when the servlet is run by two separate threads they
    > conflict somehow and cause the other to not function properly.
    >
    > The question is, how do I make sure each thread that is running

    concurrently
    > runs without affecting the other threads?
    >
    > I tried setting the servlet as Private but got a compile error.
    >


    Do you have any class attributes that are request specific?
    You should never have this situation.
    SingleThreadModel does solve this but it is highly none recommended.

    If you have much logic at all you should move it out into a Model tier
    your servlet can then become purely a 'Controller' marshalling requests,
    sessions etc.

    --
    Mike W
    VisionSet, Aug 3, 2003
    #3
  4. Steven S

    VisionSet Guest

    "Steven S" <> wrote in message
    news:96eXa.1993$2.webusenet.com...
    > > Do you have any class attributes that are request specific?
    > > You should never have this situation.

    >
    > Not sure what this means exactly, but I must otherwise it would be

    working.
    > How do I check for this?


    Post your servlet code

    >
    > > SingleThreadModel does solve this but it is highly none recommended.

    >
    > I would suppose the reason it is not recommended is because it probably
    > gives up flexibility and performance. I would most likely agree if I knew
    > how to set it up and test it. Can you point me in the right direction so
    > that I set it up in Tomcat 4.1?


    Simply implement SingleThreadModel - it's in the Servlet API
    But I shouldn't bother.

    >
    > >
    > > If you have much logic at all you should move it out into a Model tier
    > > your servlet can then become purely a 'Controller' marshalling requests,
    > > sessions etc

    >
    > I would probably agree if I could envision what a Model tier is? Can you
    > clerify?


    A full MVC (Model View Controller) paradigm explanation is here

    http://java.sun.com/blueprints/guidelines/designing_enterprise_applications_
    2e/web-tier/web-tier5.html

    It may be a little to heavy at this stage!

    Model is simply the back end of your web application, when web-apps become
    large, it is useful to put all the business logic (stuff that has nothing to
    do with the fact it is a web-app could equally well apply to a Swing GUI
    front end) in seperate classes that have no knowledge of the Front end.

    --
    Mike W
    VisionSet, Aug 3, 2003
    #4
  5. Steven S

    Steven S Guest

    > > Could you elaborate a bit on how to do this?
    > >
    > > Thanks for the response,
    > >
    > > Steve

    > public class YourServlet extends HttpServlet implements
    > SingleThreadModel{


    Worked.

    What are the consequences?

    THANK YOU.

    Steve
    Steven S, Aug 3, 2003
    #5
  6. Steven S

    Dave Miller Guest

    In article <DReXa.1005$2.webusenet.com>,
    says...
    > > > Could you elaborate a bit on how to do this?
    > > >
    > > > Thanks for the response,
    > > >
    > > > Steve

    > > public class YourServlet extends HttpServlet implements
    > > SingleThreadModel{

    >
    > Worked.
    >
    > What are the consequences?
    >
    > THANK YOU.
    >
    > Steve


    Limited. The engine will spawn a new instance for each concurrent
    request which, obviously, uses resources. If you compare the resources
    that a servlet uses processing an HTTP request and then executing an SQL
    statement versus those it takes for any GUI, you'll realize that it is
    almost impossible to get yourself in trouble unless you are spawning
    thousands of concurrent instances. If you have that level of traffic,
    nothing that you do from a coding standpoint will solve your need for
    more resources.

    Regards,

    DM
    Dave Miller, Aug 4, 2003
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andy Fish
    Replies:
    4
    Views:
    2,407
    Andy Fish
    Dec 17, 2003
  2. Sean Clarke
    Replies:
    1
    Views:
    1,881
    Sudsy
    Jan 7, 2004
  3. circuit_breaker
    Replies:
    2
    Views:
    1,989
    Jack Jia
    Apr 4, 2004
  4. javadev
    Replies:
    5
    Views:
    12,869
    javadev
    Nov 16, 2006
  5. charles cashion

    css conflict (or html conflict)

    charles cashion, Feb 18, 2009, in forum: HTML
    Replies:
    2
    Views:
    777
    charles cashion
    Feb 18, 2009
Loading...

Share This Page