How to co-work with cglib
yanxinyuan opened this issue · comments
Dears,
As far as i know, Quasar rely on bytecode instrumentation. This can be done at class loading time via a Java Agent, or at compilation time with an Ant task.
But now i have a class which is generated by cglib and i want one of its method can suspend the fiber.
Is it possible ? And how should i do?
The code is something like this:
// This class and method is generated by cglib
class Xxx {
public void yyy() throws SuspendExecution {
for (int i = 0; i < 10; i++) {
System.out.println(i);
Fiber.park();
}
}
}
public static void main(String[] args) {
// using cglib generated 'Xxx' class and 'yyy' method
Fiber<Void> fiber = new Fiber<Void>() {
@Override
protected Void run() throws SuspendExecution, InterruptedException {
Class<?> clazz = Class.forName("Xxx");
Object obj = clazz.newInstance();
Method method = clazz.getMethod("yyy");
method.invoke(obj);
return null;
}
}.start();
while(!fiber.isDone()) {
Strand.sleep(2000);
Fiber.unpark(fiber);
}
}
And the result should be:
java -jar target\Quasar-Cglib-0.0.1-SNAPSHOT.jar
QUASAR WARNING: Quasar Java Agent isn't running. If you're using another instrumentation method you can ignore this message; otherwise, please refer to the Getting Started section in the Quasar documentation.
0
1
2
Ok , after i change the cglib Interceptor to throw SuspendExecution, this issue has gone.