A bit of code was changed in Hhoj today.
In the previous app, use Threadlocal to save the user Userinfomodel for that thread. Fetched from Usersession when the thread is activated and then put into threadlocal.
Today I want to change the user name to be saved only in session. Thread activation is based on getting the latest userinfomodel from the database.
So the question came.
First, if the user name is empty, the threadlocal is not emptied.
The problem is that, in the non-logged-in state, if the previous thread is reused from the thread pool after repeated flushing,
Then the Userinfomodel in the previous threadlocal will be strung into the session and saved.
Causes the user not logged in the state to refresh several times the page becomes the sign-in state ...
(╯°-°) ╯︵┻━┻. And the first login is often the administrator (that is, me).
And this crossed is contagious. A session this accidentally gets a model that will be written to its session to save it,
The next time a new thread is encountered, it is transmitted to the next thread.
So soon all the threads have an administrator's Userinfomodel ... T.T ....
In the event of an online pool, if you use threadlocal, or another thread-key structure, every time you activate a new thread, you must clear all threadlocal ...
In the event of an online pool, if you use threadlocal, or another thread-key structure, every time you activate a new thread, you must clear all threadlocal ...
In the event of an online pool, if you use threadlocal, or another thread-key structure, every time you activate a new thread, you must clear all threadlocal ...
Important thing to say three times ...
Thread pool and ThreadLocal