Announcement Announcement Module
No announcement yet.
Calling method on the same instance that was passed Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Calling method on the same instance that was passed

    I have two objects:
    public class Caller {
    private CalledOn cO;
    Connection con;
    public Caller (CalledOn cO) {
    this.cO = cO;
    public void process () {

    public class CalledOn {
    public void begin (Caller c) {
    c.con = createConnection ();
    c.con.start ();
    public void end (Called c) {
    c.con.end ();

    I want to Aspect begin () before the process() method is called and end () after process returns. But as I do it I want to make sure that begin and end are called on the same instance of CalledOn as was passed to Caller and correct value to the Connection is being set. I am new to Spring so any help is highly appreciated..

  • #2
    Hi ,

    You can use Aspect J approach for your requirement.Create an Aspect Class which will do the logging work around your process method since we have applied the pointcut as (


    import org.aspectj.lang.annotation.Aspect;
    import org.aspectj.lang.annotation.Around;
    import org.aspectj.lang.ProceedingJoinPoint;

    public class AroundExample {

    public Object doBasicLogging(ProceedingJoinPoint pjp) throws Throwable {
    // start stopwatch
    //DO the logging Working Here when process() starts
    Object retVal = pjp.proceed();
    // stop stopwatch
    //DO the Logging after the method when process() ends
    return retVal;


    Hope this answers your question