Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spring security strategy MODE_INHERITABLETHREADLOCAL. Why?

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.

  1. Is there a memory impact with using one over the other. If so, is it significant enough?
  2. What is a typical business/functional usecase for using MODE_INHERITABLETHREADLOCAL?
  3. Any performance different with using one over the other?
like image 696
Joel Avatar asked Aug 24 '26 20:08

Joel


1 Answers

  1. The memory impact of using the two is negligible

  2. 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.

  3. Performance between the two strategies is negligible

like image 115
Rob Winch Avatar answered Aug 26 '26 22:08

Rob Winch