Question

I have an Aspect class (spring-aop). I have one advice that gets some parameters and stores it in class fields. Second advice uses these parameters. It is used in functional test, I need to make them thread-safe, because it can be run by several users simultaneously. How can I do it?

public class SomeAspect {
    private String parameters;

    public void saveParameters(JoinPoint jp) {
        Object[] args = jp.getArgs();
        Object firstArg = args[0];
        this.parameters= (String) firstArg;     
    }


    public void useParameters() {
        doSmth(parameters);
    }

}

Was it helpful?

Solution

I think you should use ThreadLocal to store parameters. According to the documentation one request will be processed with one thread, so it should be safe. Documentation is here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top