I am writing a java program which tracks as threads are created in a program and is then supposed to perform some work as each Thread terminates.
I dont see any 'thread termination hooks' out there in the javadoc.
Currently the only way I can think of to achieve my requirement is to hold on to the thread objects and query its 'state' at repeated intervals.
Is there any better way to do this?
Edit: I cannot wrap the runnable or modify the runnable in any way. My code uses runtime instrumentation and just detects that a thread is created and gets a reference to the Thread object. The runnable is already running at this point.