我理解当我们在Spring Security Strategy中使用MODE_THREADLOCAL和MODE_INHERITABLETHREADLOCAL时会发生什么以及会发生什么。 我不明白的是,为什么有人会使用MODE_THREADLOCAL而不是MODE_INHERITABLETHREADLOCAL。
使用一个而不是另一个会对内存产生影响。 如果是这样,它是否足够重要? 使用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.
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?最满意答案
使用这两者的记忆影响可以忽略不计
在某些环境中,通常会启动新线程来执行后台任务。 有时开发人员不希望创建的Thread自动包含SecurityContext。 在这些情况下,最好使用MODE_THREADLOCAL。 如果代表当前用户启动任务,则可能需要传播SecurityContext。 在这种情况下,MODE_INHERITABLETHREADLOCAL将是首选的。
两种策略之间的表现可以忽略不计
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
更多推荐
发布评论