[concurrency-interest] implementing reentrant locks with Thread.currentThread

Zhong Yu zhong.j.yu at gmail.com
Fri Nov 22 15:24:57 EST 2013


On Sun, Oct 20, 2013 at 10:21 PM, Andy Nuss <andrew_nuss at yahoo.com> wrote:
> Hi,
>
> I was wondering, if one is building a type of re-entrant lock, do you get
> better performance by paying the cost of Thread.currentThread() for each
> lock operation, or using a ThreadLocal variable.  If one chooses the latter,
> is there an impact by having lots of effective thread local storage bloat?

I guess you are not really concerned with space (how many acquired
locks could you have in a thread?) but rather the throughput (which
could be impacted by extra GC incurred by thread locals).

I have a library that heavily depends on ThreadLocal. I was concerned
with performance, so I compared it to a modified version that simply
reads/writes a static field. Amazingly I couldn't detect any
difference in performance in typical applications of the library.


>
> Andy
>
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
> http://cs.oswego.edu/mailman/listinfo/concurrency-interest
>


More information about the Concurrency-interest mailing list