Spring Request scope vs java thread-local

前端 未结 3 787
轮回少年
轮回少年 2021-01-31 04:57

In high volume (~50,000 requests per second) java web-app I\'m using ThreadLocal to execute a task which should be executed per request scope.

I could achieve the same e

3条回答
  •  无人及你
    2021-01-31 05:14

    The Spring solution will cost more but will make for cleaner code IMO. There are a lot of steps involved in fetching, creating, initializing, and storing a bean. However you won't have to think about clearing the request scoped bean as you would the ThreadLocal. It will be collected when the corresponding ServletRequest is cleaned up.

提交回复
热议问题