Java ThreadLocal singleton – what is it?

Laymen say, what does it mean when someone says that an object is a thread singleton in Java? I'm attending a lecture on Java Server faces. Every time I talk about facescontext - the lecturer always reminds us that this is a single threaded single person

Solution

Each thread has only one unique instance of facescontext

Facesservlet creates a ThreadLocal < facescontext > at the beginning of the HTTP servlet request and deletes it at the end of the HTTP servlet response associated with the HTTP servlet request Whenever you execute facescontext#getcurrentinstance() in JSF code, you will always get the same instance in the whole HTTP servlet request / response processing

Since HTTP servlet requests are executed by different threads and facescontext instances are attached to a single thread as thread local variables, no two HTTP servlet requests share the same facescontext instance

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>