When the browser sends the same request to multiple tabs


The reason for this is that the new development younger brother wrote a blocking request in the controller and directly used while (true). When throwing an exception, the jump out condition inside will never be satisfied. (of course, we found it when we submitted the code)

So we studied how he would affect the program.

First of all, our theoretical knowledge is that when Tomcat receives a request, it will take an idle thread from the thread pool to process the request, so the dead loop is limited to the current thread. When another request is initiated, it will also be a new thread, so the request will not respond, However, it will not cause the program to hang up directly (Tomcat can spare up to 200 threads and hold a small number of requests tested by itself).

So when I open two browser tab pages and send the same request at the same time, I check the console display.

When the browser sends the same request to multiple tabs

Threads are really different, but why is the request time more than 20 seconds different?

At first I thought there was something wrong with my theoretical knowledge. Then I thought for a while and opened a new browser to do it again.

One request is sent with edge and the other request is sent with chrome. At this time, the time interval between the two requests is the time difference of carriage return.

Therefore, there must be some mechanism inside the browser to prevent multiple tab pages from making requests for the same URL (blocking).

After checking the information, there is a solution on it.

1. As long as the cache of the browser is disabled, it will be found that there is no serialization problem
At this time, multiple requests are initiated at the same time and end at the same time after 5S
2. If the browser’s cache is not disabled
The browser expects the same URL server to return 304 response, but unfortunately, the first response content is not cached, so each request is serial, and the execution order is 5S + 5S + 5S
But if the browser sends a cache response, then
If 5S is executed for the first time and cache is executed after that, the execution order is 5S + 0 + 0
In conclusion, this function is actually prepared for the pictures on the web page

There are also some loopholes in the above logic. In fact, there should be a timeout period. During the timeout period, it will block. After the timeout period, a new request will be initiated.

Open the developer page under edge and click settings

When the browser sends the same request to multiple tabs

So I tried to open three tabs and open the developer page at the same time. The back end can respond directly.

Therefore, the reason for this phenomenon is that the browser will cache large files / pictures to improve the loading speed.

The original address of the information found looks like a translated page.

The serialization problem of opening the same URL with multiple tabs in the browser – corner of wind and snow (laruence. Com)

Recommended Today

Building the basic static page of Vue chat room

design sketch HTML: <template>     <view>         <view>             <scroll-view scroll-y=”true”>                 <div> <!– Message notification — >                     <div>                         <div>2021-12-28 16:50:00</div> < div > XXX processed this work order < / div >                     </div> <!– Left — >                     <!– <div></div> –> <!– Right — >                     <!– <div></div> –>               </div>               <div>                 <div>                     <image src=”../../static/logo.png”>                     <div>                         <div>2021-12-28 16:50:00</div> < […]