java - @Async Spring gets recalled for every request of different sessions -


i have spring @async annotated method in bean, in controller call bean's method on user request, , way can progress bean, , works fine that.

but when open session controller appears restart method , progress again start point.

how correctly, have progress count number field in bean. , increment in @async method via ajax request in controller retrieves bean.

but controller have 1 bean injected it. or there 1 controller whole app, whats wrong here ?

edit

i tested in opening 2 different browsers , running task gets reloaded in both.

apparently spring controllers singletons per web app (and when think should be), not thread safe if have component wired it.

meaning suppose have bean a wired controller ac if 2 users send requests ac method uses bean a @ same time, you'll have wrong values both or you'll have bean reconstructing @ each call, if user1 starts task , after while before task finished user2 comes play , wants start too, user1' values reset , on.

to avoid found should make beans wired controllers annotated session scoped using annotations or xml.

in case used

@scope("session") 

you should never annotate controller, won't work , if give weird behavior.

you should (if using annotations me) add scoped-proxy="targetclass" in <context:component-scan /> element


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -