[undertow-dev] Cache object that is not thread safe

Bill O'Neil bill at dartalley.com
Thu Apr 5 07:50:04 EDT 2018


If it's actually a util object can you make it stateless so that it is
thread safe? Maybe add an additional context type object for state if you
really need it. Attaching it to the exchange as an attachment could work.

On Thu, Apr 5, 2018 at 7:36 AM, Steve Hu <stevehu at gmail.com> wrote:

> I was thinking about ThreadLocal as it is very popular in Java EE but one
> request might be handled by multiple threads from IO thread to worker
> thread which means you have to instantiate as many objects as the number of
> total threads. Just trying to find if there are any better solutions.
> Thanks for your confirmation.
>
> On Thu, Apr 5, 2018 at 7:19 AM, Stuart Douglas <sdouglas at redhat.com>
> wrote:
>
>> If you want one per thread just use ThreadLocal.
>>
>> Stuart
>>
>> On Thu, 5 Apr. 2018, 7:42 pm Steve Hu, <stevehu at gmail.com> wrote:
>>
>>> I need to share the same instance of a "Util" object to reuse it in all
>>> the handleRequest calls. Where is the best place to store the Util object
>>> instance? The Util class is not thread safe, so I should have one
>>> instance for each client thread.
>>>
>>> Thanks,
>>>
>>> Steve
>>>
>>> _______________________________________________
>>> undertow-dev mailing list
>>> undertow-dev at lists.jboss.org
>>> https://lists.jboss.org/mailman/listinfo/undertow-dev
>>
>>
>
> _______________________________________________
> undertow-dev mailing list
> undertow-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/undertow-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/undertow-dev/attachments/20180405/a2b142ab/attachment.html 


More information about the undertow-dev mailing list