[concurrency-interest] ThreadLocal.getIfPresent()

Peter Levart peter.levart at gmail.com
Wed Jun 6 13:09:56 EDT 2018


Di David,

On 06/06/18 18:48, David Lloyd wrote:
> On Wed, Jun 6, 2018 at 10:17 AM, Peter Levart via Concurrency-interest
> <concurrency-interest at cs.oswego.edu> wrote:
>> Hello,
>>
>> I thought I'd ask on this list, whether the following new method on
>> ThreadLocal class would be useful, desirable or undesirable:
> I'd find it useful, but adding it (compatibly) would be very
> difficult.  Classes which have overridden get() would have unexpected
> behavior, etc.
>

Are you thinking about possible "inconsistency" between overridden get() 
and not overridden getIfPresent() ? Like for example:


public class TenTimesThreadLocal extends ThreadLocal<Integer> {
     @Override
     public Integer get() {
         return super.get() == null ? null : super.get() * 10;
     }

     @Override
     public void set(Integer value) {
         super.set(value == null ? null : value / 10);
     }
}


Peter

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20180606/b8d0faa8/attachment.html>


More information about the Concurrency-interest mailing list