The previous understanding of cookies and sessions is that cookies are generated by the server and stored in the browser, while sessions are stored in the server. Each user has a unique Session. When we users log in, we will pass the SESSIONID in the Cookie, To correspond to the SESSION in the server, so as to obtain the information in the SESSION. The default duration of the SESSION in the Tomcat server is 30 minutes (expired after 30 minutes calculated from the last SESSION access).

Through a project, I learned more about Cokie and SESSION. If our server has a high concurrency, which can be interpreted as a large number of accesses within 30 minutes, then our server will store a large number of sessions, which will cause a lot of pressure on the server (even if not a large number of accesses, Saving sessions on the server also slightly affects the server), hence the following “Session”

To solve the pressure of saving Session in the server, we save the Session data in the database. We create a table with SESSIONID and userId in it. When a user logs in, we use the SESSIONID in the Cookie. To query the SESSIONID of the database to get userId, and then get user information, can realize the function of Session, but when high concurrency occurs, because it is the user queried in the database, we cannot know which user the current user corresponds to, so multithreading comes into use. ThreadLocal

provides the ability to store variables in a thread. The difference is that the variables read by each thread are independent of each other. ThreadLocal

provides the ability to store variables in a thread. ThreadLocal (ThreadLocal, ThreadLocal, ThreadLocal, ThreadLocal, ThreadLocal, ThreadLocal, ThreadLocal, ThreadLocal, ThreadLocal, ThreadLocal, ThreadLocal);