I would like to know if there is a way in AspectJ to declare an aspect per each thread, and also if there is a way to declare an aspect per team of threads?
By team of threads I am referring to this example:
A given thread ‘X’ creates ‘N’ new threads, then ‘X’ is the master of this team, if a given thread ‘Y’ within this team also creates by them self a new team, ‘Y’ will became the master of this new team. So I would like to know if I can declare an aspect ‘A’ to the team produce by the thread ‘X’ and a different “instance” of the aspect ‘A’ for the team ‘Y’.
AspectJ manipulates only byte code. So it cannot determine the runtime information(you know thread where code is invoked is runtime information) when generating Aspects hook.
If you need to create thread unique state use ThreadLocal.
If you need to create ThreadGroup unique state you should do some manual work. See how it can be implemented: ThreadGroup local variables. Also be aware in Java you cannot determine parent thread, so you need to use ThreadGroup.
And every time when you want to use ThreadLocal state and Aspects, think about your program design, is it right way for you?