Are there thread group-local variables in Java?

前端 未结 3 1491
失恋的感觉
失恋的感觉 2020-12-29 13:40

I am looking for a class similar to ThreadLocal which would work on thread groups instead of threads.

If there is not such a class (in some open source library) how

3条回答
  •  孤独总比滥情好
    2020-12-29 14:20

    The last time i looked at the implementation (well a few years ago) Thread Locals were implemented as a simple hash table indexed by the thread id. Nothing fancy and miles away from the efficiency of C++.

    You can do the same and use the thread group object as a key for your own thread group locals hash table.

提交回复
热议问题