spring 安全策略 MODE_INHERITABLETHREADLOCAL.为什么? [英] spring security strategy MODE_INHERITABLETHREADLOCAL. Why?
问题描述
我了解在 Spring Security Strategy 中使用 MODE_THREADLOCAL 和 MODE_INHERITABLETHREADLOCAL 时会发生什么以及会发生什么.我不明白的是,为什么有人会使用 MODE_THREADLOCAL 而不是 MODE_INHERITABLETHREADLOCAL.
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.
- 使用其中一种是否会对内存产生影响.如果是这样,是吗足够重要吗?
- 使用 MODE_INHERITABLETHREADLOCAL 的典型业务/功能用例是什么?
- 使用一种与另一种相比有什么不同的表现吗?
推荐答案
使用两者对内存的影响可以忽略不计
The memory impact of using the two is negligible
在某些环境中,启动新线程来执行后台任务是很常见的.有时,开发人员不希望创建的 Thread 自动包含 SecurityContext.在这些情况下,MODE_THREADLOCAL 更可取.如果您代表当前用户启动任务,则可能需要传播 SecurityContext.在这种情况下,最好使用 MODE_INHERITABLETHREADLOCAL.
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
这篇关于spring 安全策略 MODE_INHERITABLETHREADLOCAL.为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!