Thread creation listener

前端 未结 3 537
灰色年华
灰色年华 2021-01-05 07:59

Is it possible to write Thread creation listener in java? For example using aop?!

I mean something like this that if my application creates a thread I would like to

3条回答
  •  不知归路
    2021-01-05 08:26

    Perhaps a ThreadGroup is what you need. All Threads are members of a ThreadGroup and when you start a new Thread it is added to the same group as its parent by default.

    In theory its possible (but not recommended) to sub-class to be notified when a Thread is added or removed from the group.

    It is likely that polling the threads of this groups, or polling all threads is a better solution.

提交回复
热议问题