File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes servlet stuff is not parallel? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "servlet stuff is not parallel?" Watch "servlet stuff is not parallel?" New topic
Author

servlet stuff is not parallel?

paul wheaton
Trailboss

Joined: Dec 14, 1998
Posts: 20528
    ∞

I'm using tomcat, but my question is for servlet stuff in general as well as for tomcat.

I'm trying to do some testing of something else, but I ended up making a servlet that does nothing more than Thread.sleep() for ten seconds. Then I open three browsers and have each browser hit the servlet. It takes me about two seconds to kick of the next browser manually, so I figure that the three browsers will each stop with a two second delay between each. But! It's a ten second delay!

The servlet stuff is running in serial!!!

I figured it would run in parallel.

What's up with that?


permaculture Wood Burning Stoves 2.0 - 4-DVD set
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60992
    
  65

There must be something else going on to account for your delay. Unless you have declared your servlet using the deprecated SingleThreadModel, each request will run in its own thread independent of the other threads.

Are you performing any synchronization within your servlet code?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
paul wheaton
Trailboss

Joined: Dec 14, 1998
Posts: 20528
    ∞

No SingleThreadModel stuff.

No synchronization code.

Just does the 10 second delay and then sends "OK" back to the browser.

I'm stumped.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60992
    
  65

Me too. Wanna post your code?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Bear Bibeault:
There must be something else going on to account for your delay. Unless you have declared your servlet using the deprecated SingleThreadModel, each request will run in its own thread independent of the other threads.

Are you performing any synchronization within your servlet code?


Even with SingleThreadModel, they would run parallel.
The difference is that each request would have its own instance of the servlet.

Posting the code would be helpful.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
paul wheaton
Trailboss

Joined: Dec 14, 1998
Posts: 20528
    ∞



I whittled the code down to this. The problem still exists.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Make sure it's not your browser making the requests synchronously.

I just put your code into a project and tried it with two browsers and then build a page with 5 frames that all point to the same servet.

With Firefox, the requests were stacked up and 5 requests took 10 seconds.
With Konqueror, they came back in a random order and it took a litte more that 3.

To further test, I pointed a threaded load tester that I wrote at it and ran it with 20 requests. It finished in 3.615 seconds.

Using a packet sniffer, I could see that the requests/responses were synchronized with Firefox but not with Konqueror or my load tester.
 
wood burning stoves
 
subject: servlet stuff is not parallel?