Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt about code to test 'one thread per request'

 
Ha Minh Nam
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody!
I'm preparing for SCWCD, reading HFSJ book. The book said:

The container runs multiple threads to process multiple requests to a
single servlet... Each request runs in a separate thread


So I wrote a simple servlet to do a checking. My servlet overrides doPost() method, and in the method body I simply print out hashcode of the servlet; Name, ID and hashcode of the current thread that is executing this method. The code is as follow:



Use FireFox to make a request, the response likes this:



I press F5 multiple times to simulate 'multiple requests', but the response doesn't change at all. What I expected is that the thread name, id, and hashcode change to other values for every request.

Could anyone explain this?
 
Felix Li
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good to test around like that.
The Container should init a thread for each client(aka browser). Therfore, if you keep on refreshing on the same browser, info remains the same. Try using several browser to test it. It should work.
 
Ha Minh Nam
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Felix Li:
Good to test around like that.
The Container should init a thread for each client(aka browser). Therfore, if you keep on refreshing on the same browser, info remains the same. Try using several browser to test it. It should work.


Sorry, I missed the point is I tested with 3 browsers: FireFox, IE and Chrome, the response was still not change. I inserted a line of code at beginning of doPost() method:



Then I checked the container's log file for every request. I assure that every request made from browser was really hit to the servlet, the response was not cached somewhere.

My servlet is running in Apache Tomcat.

What was happen in the container?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic