threadlocal variables in a servlet

前端 未结 5 1474
渐次进展
渐次进展 2020-12-15 13:04

Are the threadlocals variables global to all the requests made to the servlet that owns the variables?

I am using resin for the server.

Thanks for awnser.

5条回答
  •  孤街浪徒
    2020-12-15 13:28

    Short answer: Yes.
    A bit longer one: This is how Spring does its magic. See RequestContextHolder (via DocJar).

    Caution is needed though - you have to know when to invalidate the ThreadLocal, how to defer to other threads and how (not) to get tangled with a non-threadlocal context.

    Or you could just use Spring...

提交回复
热议问题