4

I already know that most implementations use a single thread, but is there anything in the specification that implies the single thread? I remember reading about distributed app servers which use a cluster of JVMs. Are there any such implementations? Or are there any such implementations possible? What do the specifications imply for such distributed implementations, and would such an implementation guarantee the single thread?

necromancer
  • 23,916
  • 22
  • 68
  • 115

1 Answers1

12

The relevant servlet spec 3.0 fragment:

6.2.3 Filter Environment

A Filter and the target servlet or resource at the end of the filter chain must execute in the same invocation thread.

Also there are too many frameworks that rely on ThreadLocal set in one of the filters. If different thread was running filters and other calling the servlet (technically possible) they would all be broken.

Note that distribution only applies to separate requests, i.e. different servers in the cluster handle different requests. I have never heard about splitting a single request into to machines.

Community
  • 1
  • 1
Tomasz Nurkiewicz
  • 334,321
  • 69
  • 703
  • 674
  • followup question - is `request.setAttribute(...)` worth using at all for general purpose programming (as opposed to JSPs) in favor of ThreadLocal? (this is assuming the threadlocals are cleaned up correctly after each request.) it seems that the type-safety of threadlocals makes them a better candidate than type-unsafe request attributes. additionally, the performance is better because you are not dealing with string keys, hashing, and maps. – necromancer Apr 10 '12 at 21:01
  • http://stackoverflow.com/questions/10096483/is-threadlocal-preferable-to-httpservletrequest-setattributekey-value – necromancer Apr 10 '12 at 21:09