I\'m looking for a Java solution that would allow me to use AOP to weave new code on top of already running code at runtime. The key is not to require the restart of the JVM. Al
A few things to consider:
Having said that, you either can try concepts such as OSGi or write your own class loader (or find one of many existing ones on the Internet) which loads each class or each JAR in a separate classloader instance. This can get arbitrarily complex, so maybe you want to consider this simple approach as long as it is within the technical bounds of your situation:
This solution satisfies your conditions that it can be (de)activated dynamically and that no JVM restart is necessary after the aspect code has been woven.
You can Implement an ASM solution that would allow to weave new code on top of already running code at runtime (with no downtime)
You might can use the same solution to remove the woven at runtime
Aspect
An aspect is the cross-cutting functionality you are implementing. It is the aspect, or area, of your application you are modularizing. The most common (albeit simple) example of an aspect is logging. Logging is something that is required throughout an application. However, because applications tend to be broken down into layers based on functionality, reusing a logging module through inheritance
does not make sense. However, you can create a logging aspect and apply it throughout your application using AOP.
Weaving
Weaving is the process of applying aspects to a target object to create a new, proxied object. The aspects are woven into the target object at the specified joinpoints. The weaving can take place at several points in the target class’s lifetime:
(Source)