Container是如何工作的
Less than 1 minute
Java web 应用通常会跑在 Container上面,比如人尽皆知的 Tomcat。下面我们来看下 Tomcat 是怎么工作的
工作流程
![202403270918356240](/assets/202403270918353748121-qOyMWT7I.png)
![202403270920276841](/assets/202403270920276035118-ChlSlXXq.png)
![2024032709204302](/assets/202403270920430575932-CNeRiXnU.png)
![202403270921026543](/assets/202403270921028752946-DSXf0M-R.png)
![202403270921166004](/assets/20240327092116700177-DLNVss83.png)
![20240327092947556](/assets/202403270929472208099-BW3uTRO7.png)
The servlet lifecycle is simple; there’s only one main state—initialized.If the servlet isn’t initialized, then it’s either being initialized (running its constructor or init()method), being destroyed (running its destroy() method), or it simply does not exist.
![202403270931448417](/assets/202403270931449757049-CY0Zs3QA.png)
The Three Big Lifecycle Moments
![202403270932137028](/assets/202403270932134037123-2ObU769D.png)
The Container runs multiple threads to process multiple requests to a single servlet
![202403270934049069](/assets/202403270934049261619-BpruG3qW.png)