How tomcat handle multiple concurrent request at the same time ?
Does it queues up the requests or processes some of the requests in parallel ?
If it processes requests in parallel , how does it returns the asynchronous response ? Does it keeps the connection open with client until response comes ?
If the tomcat uses a multi threaded environment ? Does the code needs to completely thread safe ? Or tomcat handles it on its own.
Tomcat uses thread connection pool and each incoming request will be assigned to a thread from the pool and once thread finishes the job, it return to the pool.
You can configure the tomcat connection pool according to your application.
Apart from connection pool, tomcat internally uses the JDBC connection pool as well, read more here https://tomcat.apache.org/tomcat-7.0-doc/jdbc-pool.html.
Edit :- to answer your second question, yes tomcat uses multi-threaded env. and each request is tomcat is assigned to a new thread for example each servlet request will be wrapped to a new request object(thread-safe) but after that it depends on your business logic, whether you are passing it to some thread safe code or not.
Will add code sample later on but http://jcip.net/ is a very good starting point if you want more code samples and deep understanding of it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With