method « aspectj « Java Enterprise Q&A

1. Use aspectj to profile selected methods

I'd like to use aspectj to profile a library. My plan was to mark methods that require profiling with an annotation: @Profiled("logicalUnitOfWork") And then have an aspect that would fire before and ...

2. Aspectj. Creating innter type methods in multiple classes

If I put:

public CountryState CountryState.find(long id) {
        return (CountryState) findById(CountryState.class, id);
I'm creating a method find in the class CountryState. Is there a way to create ...

3. How can I make external methods interruptable?

The Problem

I'm running multiple invocations of some external method via an ExecutorService. I would like to be able to interrupt these methods, but unfortunately they do not check the ...

4. Restricting method calls to 1 per sec with Java?

I am writing a program, and I would only like the user to be able to make certain method calls every 1 second. I'm having trouble figuring out the best way ...

5. Pointcut to match all calls to public methods, except calls to self

I am attempting to write an aspect which monitors calls to public methods on a variety of objects, but ignore calls to self. For this, I have an aspect like this:

abstract ...

6. How to get the caller method information from Around advise

ThisJoinPoint can only get the current method information, anyway to get the caller method information?

7. Determining which method triggered an aspect

I was wondering if there is anyway of determing what mehtod was active when this aspect was triggered. I found the method JointPoint.getSourceLocation() which returns the source code line. I realised ...

8. AspectJ - pointcut on native method call

Is it possible to set pointcut on native method call with AspectJ? I tried following aspect:

public aspect EmailAspect {
    pointcut conn() : call(*;
    before() ...

9. AspectJ pointcut to method call in specific methods

I want to create a pointcut to target a call to a method from specific methods. take the following:

class Parent {
   public foo() {
     //do something

10. Can aspectj add methods to java.lang.String

I've read some articles of aspectj, I know it can enhance classes, which is attractive. I've a very stupid question that I can't find a clear answer: Can aspectj add methods to ...

11. Getting return type of generic method call in AspectJ

I've got generic method

class Foo {
    static native T <T> foo();

Bar bar =;
What I need is to replace calls to this method using AspectJ. The problem ...

12. How to generate a unique hash code for a method instance?

I am doing some profiling with Aspectj. I need to identify uniquely the instances of a method where the field been accessed For example:

public class Class{ int a; int b;
public void method1(){


13. Cannot override method and cannot access field while using idiom "Providing a default interface implementation"

Here is code:

public interface IDefaultInterface {
    public void m1();   
    static aspect Impl{
        public int f1;

14. Is it possible to retrieve the object instance performing a method call with AspectJ?

Let's imagine the following aspect:

 aspect FaultHandler {

   pointcut services(Server s): target(s) && call(public * *(..));

   before(Server s): services(s) {
     // How to ...

15. How can I synchronize over Java aspects defined around a method?

I have a Hibernate transactional method "doImportImpl" which runs multi-threaded. Certain records however need to be imported in sequence, so the code structure is roughly like this:

public RecordResult doImportImpl(String data) {

16. AspectJ MethodSignature Returns Null Method

Hi. I'm relatively new to AspectJ (used in the past, but not for a while, so I'm a little bit rusty). I've setup a pointcut to catch all method calls, which it does, and then in the advice, I'm trying to print out the actual method that was called. I can do that using the following: thisJoinPoint.getSignature().toString() and that works just ...