After a few days learning byte buddy, I finally know why we can not instrument
ThreadPoolExecutor when we have used it in the agent.
See the following code that byte buddy generates:
public class ThreadPoolExecutor extends AbstractExecutorService implements
EnhancedInstance {
//...
private volatile Object _$EnhancedClassField_ws;
//...
}
The agent add a field in the ThreadPoolExecutor class.
When config is AgentBuilder.RedefinitionStrategy.RETRANSFORMATION and
disableClassFormatChanges, we will see the error:
java.lang.IllegalStateException: Cannot define field for frozen type: class
java.util.concurrent.ThreadPoolExecutor
Now the problem is clear.
Jvm can not change the class structure when a class has already been loaded.
If we just want to make a aspect for ThreadPoolExecutor#execute method, we
don't need to add a field.
So if we can do something here?