• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

servlet stuff is not parallel?

 
Trailboss
Posts: 23778
IntelliJ IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 23778
IntelliJ IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Me too. Wanna post your code?
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 23778
IntelliJ IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I whittled the code down to this. The problem still exists.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic