javaconcurrencyaopaspect

AspectJ in multithreading


Currently im working on a application that runs the same process(with different input parameters in this case TaskInformation) parallelly on 16 threads. I would like to create Aspect from which i would take parameters and values and store them in a Object that i would create inside Aspect.

My question is this object which is created independent for every thread and can i somehow call the exact instance of the object so i can store right values for each thread.

I would avoid threadLocal if possible since this is something i currently use without aspect and i hope i can avoid it if possible.

Thanks for helping in advance!

Im using threadLocal and i would like to refactor this.

Edit: We have a Process class in which we are looking at process method, this method is running simultaneously in multiple threads. I would like to fill up the LoggingObject with information for every thread and at the end log them as a summary of the whole processing.

Example:

    public aspect MyAspect {

private final LoggingObject log = new LoggingObject()

        pointcut processMethodExecution(TaskInformation taskInfo):
        execution(TaskStatus Processor.process(TaskInformation)) && args(taskInfo);

        after(TaskInformation taskInfo): processMethodExecution(taskInfo) {
        logger.info("Processing task with ID: " + taskInfo.getTaskId());
        log.setID(taskInfo.getTaskId())
        }
        }

Solution

  • You have several options: