Introducation
What is a Java Agent?
In general, a java agent is just a specially crafted jar file. It utilizes the Instrumentation API that the JVM provides to alter existing byte-code that is loaded in a JVM.
For an agent to work, we need to define two methods:
- premain – will statically load the agent using -javaagent parameter at JVM startup
- agentmain – will dynamically load the agent into the JVM using the Java Attach API
An interesting concept to keep in mind is that a JVM implementation, like Oracle, OpenJDK, and others, can provide a mechanism to start agents dynamically, but it is not a requirement.
Refer
https://www.baeldung.com/java-instrumentation
https://juejin.im/post/5ac32eba5188255c313af0dd
https://www.ibm.com/developerworks/cn/java/j-lo-jse61/index.html
http://www.iocoder.cn/SkyWalking/agent-plugin-system/