Open GoogleCodeExporter opened 9 years ago
Description of the issue:
using thread pool in AOP: fixedPool.submit
there is weird that fixedPool.submit called a lots times
Steps to reproduce:
let:
final ExecutorService fixedPool = Executors.newFixedThreadPool(10);
@AsyncDBCall
public void ssss(){
System.out.println("ssss");
}
when calling:
@Test
public void aa2222(){
instance.ssss();
}
if I wrote a interceptor (1) or (2), I got:
AsyncDBCall1
AsyncDBCall2
AsyncDBCall1
AsyncDBCall2
AsyncDBCall1
AsyncDBCall2
AsyncDBCall1
AsyncDBCall2
AsyncDBCall1
...
AsyncDBCall2
AsyncDBCall1
AsyncDBCall2
AsyncDBCall1
AsyncDBCall2
AsyncDBCall1
AsyncDBCall2
ssss11
(1) bindInterceptor(Matchers.any(),
Matchers.annotatedWith(AsyncDBCall.class), new MethodInterceptor() {
@Override
public Object invoke(final MethodInvocation invocation) throws Throwable {
System.out.println("AsyncDBCall1");
return fixedPool.submit(new Callable<Object>() {
@Override
public Object call() throws Exception {
try {
System.out.println("AsyncDBCall2");
return invocation.proceed();
} catch (Throwable throwable) {
throw Throwables.propagate(throwable);
}
}
});
}
});
(2) bindInterceptor(Matchers.any(), Matchers.annotatedWith(AsyncDBCall.class),
new MethodInterceptor() {
@Override
public Object invoke(final MethodInvocation invocation) throws Throwable {
System.out.println("AsyncDBCall1");
fixedPool.submit(new Runnable() {
@Override
public void run() {
try {
System.out.println("AsyncDBCall2");
invocation.proceed();
} catch (Throwable throwable) {
throw Throwables.propagate(throwable);
}
}
});
return null;
}
});
using:
/usr/lib/jvm/java-6-openjdk-amd64/bin/java
Original comment by chenwei...@gmail.com
on 14 Aug 2013 at 2:35
Attachments:
AOP in Guice does not allow offloading the invocation to a separate thread.
Original comment by sberlin
on 14 Aug 2013 at 2:44
thank you very much
Original comment by chenwei...@gmail.com
on 14 Aug 2013 at 2:52
Original issue reported on code.google.com by
chenwei...@gmail.com
on 14 Aug 2013 at 2:33Attachments: