Performance problems when using lots of AOP request scoped beans

前端 未结 3 1527
星月不相逢
星月不相逢 2021-02-14 22:51

I\'m working on a semi-large application using Spring 3 and am running into performance problems when throwing hundreds of users at it at once. I\'m using several request scope

3条回答
  •  攒了一身酷
    2021-02-14 23:29

    One option is to replace injecting a scoped proxy with a lookup-method:

    public abstract class ExecutingClass {
        protected abstract SomeInterface makeMyBean();
    
        public void execute() {
            SomeInterface myBean = makeMyBean();
            String property = myBean.getProperty1(); 
            String otherProperty = myBean.getProperty2(); 
        }
    }
    

    That will ensure Spring is asked for the bean only once per request, eliminate any overhead due to the scoped proxy, and shorten stack traces. It is less flexible (in that you can not arbitrarily share references to the request scoped bean and have the scoped proxy use the right bean) but you might not need the flexibility.

提交回复
热议问题