Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is a single thread guaranteed to execute a Servlet and its Filters?

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?

like image 659
necromancer Avatar asked Dec 16 '22 01:12

necromancer


1 Answers

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.

like image 105
Tomasz Nurkiewicz Avatar answered Feb 15 '23 23:02

Tomasz Nurkiewicz