Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tomcat inter webapp http communication

Given two web apps running on the same Tomcat 6. If you do an http-call from one app to the other, will Tomcat "short circuit" this call, or will it go all the way out on the interwebz before calling home?

@thomasz answer shows the need for more detail. We're using Springs RestTemplate to do the communication. Its plugable architecture lets you provide your own ClientHttpRequestFactory.

Would it be possible to implement a ClientHttpRequest that, if the request was to localhost, it could persuade tomcat to handle it internally?

like image 389
slipset Avatar asked Apr 19 '26 08:04

slipset


1 Answers

No, the request will go through all the layers, including loopback interface. Tomcat is not treating requests to the same web container differently. After all, how? You are accessing some URL via URLConnection or HttpClient or raw socket or... - Tomcat would have to somehow intercept (instrument) your application's code and dynamically replace HTTP call with some internal invocation. Possible, but very complicated.

To make matters worse, you can easily cause deadlock or starvation under high load. Imagine your Tomcat worker thread pool has 10 threads and at the same time you access the same servlet from 10 concurrent users. Every servlet now tries to connect to the same web container, but the worker thread pool is exhausted. So all these servlets are blocking, waiting for idle worker thread. But this will never happen, because they are occupying all of them!

like image 94
Tomasz Nurkiewicz Avatar answered Apr 22 '26 05:04

Tomasz Nurkiewicz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!