开发者

How to grab a thread that accesses a method?

开发者 https://www.devze.com 2023-03-28 07:08 出处:网络
I am working on a lock class to learn more on concurrency. What I am trying to do 开发者_开发百科is create a queued lock. A thread calls lock, is added to a queue and when the lock is released and the

I am working on a lock class to learn more on concurrency. What I am trying to do 开发者_开发百科is create a queued lock. A thread calls lock, is added to a queue and when the lock is released and the thread is first in line of the queue, it will be able to continue.

What I would like to know is: is there a way I can grab the thread that is currently running the lock code or do I have to pass the thread object into the lock as a parameter?


The static method Thread.currentThread returns a reference to the currently executing Thread object.

0

精彩评论

暂无评论...
验证码 换一张
取 消