Search code examples
javamultithreadingwebserverthreadpool

Are threads shared among web modules?


I know that web servers use thread pools to spare expensive thread creation operation. My question is, are the thread pools shared amond different modules deployed on the same web server?

In particular, we have two web modules deployed. A filter defined only in one module sets a threadlocal variable (and never unsets it). Would that be threadlocal also visible in another web module, as a result of the same thread being reused there?

thanks


Solution

  • I am not sure about all servers but in case of Tomcat, the thread pool is set for the given port. So if your modules are deployed under different ports then each of them will have the separate thread pool. So the threadLocal would be only visible for given module.

    Sample extract from Tomcat config. I am guessing that the other servers use similar approach.

    enter image description here