问题
I understand how and what happens when we use MODE_THREADLOCAL and MODE_INHERITABLETHREADLOCAL in Spring Security Strategy. What I don't understand is, why would someone use MODE_THREADLOCAL over MODE_INHERITABLETHREADLOCAL.
- Is there a memory impact with using one over the other. If so, is it significant enough?
- What is a typical business/functional usecase for using MODE_INHERITABLETHREADLOCAL?
- Any performance different with using one over the other?
回答1:
The memory impact of using the two is negligible
In some environments, it is common to spin up new Threads to do background tasks. Sometimes developers do not want the Thread that is created to contain a SecurityContext automatically. In these instances, MODE_THREADLOCAL is preferable. If you spin up a task on behalf of the current user, then it may be desirable to propagate the SecurityContext. In this instance MODE_INHERITABLETHREADLOCAL would be preferrable.
Performance between the two strategies is negligible
来源:https://stackoverflow.com/questions/31967886/spring-security-strategy-mode-inheritablethreadlocal-why