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

Steve Hu stevehu at gmail.com
Thu Apr 5 08:21:38 EDT 2018


Thanks. This is another option to explore. The question was asked on behalf
of another user on another forum. I am going to find more info about the
use case. Will pass your answers to him.

On Thu, Apr 5, 2018, 7:50 AM Bill O'Neil, <bill at dartalley.com> wrote:

> 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/0daaa3a9/attachment-0001.html 


More information about the undertow-dev mailing list