Particular Thread Count

后端 未结 5 761
花落未央
花落未央 2021-01-24 01:11

I want to know how many active threads are there for a particular Thread class. Lets say I have a class T which extends thread. In some other class (Ex: Demo) , I want to get t

5条回答
  •  鱼传尺愫
    2021-01-24 02:07

    Your Thread (or Runnable) subclass can maintain a static active count. Increment when run() starts, decrement when run() ends (in a finally block).

    Make sure the increment/decrement is done in a multithread secure way.

提交回复
热议问题