java - Spring MVC context beans: Is it bad to modify objects from getBean()? Threading concern -


i have bunch of objects use, on every page load change properties of object.

for example: /bob/dave-10

will show information bob's child named dave @ age 10, such in controller:

child child = (child)context.getbean("child_"+childname); child.setage(childage); model.addattribute("child", child); return "jsp_page"; 

but person can go to: /bob/dave-11 see dave's information @ age 11.

at dave-10, change child object's age property 10. @ dave-11, change same property 11.

i fear may cause race condition two+ people visit different ages dave, , 1 person receive other's page.

can happen? or should not worry? not using synchronized/thread locking anywhere. if problem, how should best approach this? cloning every object? or there way create new object every time getbean?

is there way create new object every time getbean?

yes. make bean prototype-scoped, using @scope("prototype"), or corresponding xml.

but feel class shouldn't spring component @ all, , should create new instance every time need one.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -