• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

servlet stuff is not parallel?

 
paul wheaton
Trailboss
Pie
Posts: 21390
Firefox Browser IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64721
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
paul wheaton
Trailboss
Pie
Posts: 21390
Firefox Browser IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64721
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Me too. Wanna post your code?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
paul wheaton
Trailboss
Pie
Posts: 21390
Firefox Browser IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I whittled the code down to this. The problem still exists.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic