Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

Scope Request

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

We are using spring framework to develop our web application.
To solve concurrency issue , we have decided to use scope request.
Can any one tell us the advantages/disadvantages of using scope request

Thanks
Rajesh
 
Sheriff
Posts: 21922
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to our Spring forum.
 
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Rajesh Santhanakrishnan wrote:Hi,

We are using spring framework to develop our web application.
To solve concurrency issue , we have decided to use scope request.
Can any one tell us the advantages/disadvantages of using scope request

Thanks
Rajesh



What do you mean advantages/disadvantages? Request scope means, in terms of Spring beans, that each HttpRequest will get their own instance of a bean set at request scope. If that is truly the scope you need that bean to be in, then make it that scope. Also note, that if there is not an HttpRequest then it will just default back to Singleton.

When you are changing scopes and you have one bean refer to another bean at a different scope, then look to Spring 3.x <aop:scoped-proxy/>

When it comes to concurrency, it depends on what you are storing. For instance, 99% of my beans are always Singleton, because they don't hold any state, and a single instance can therefore handle as many threads running at the same time through it as the Operating System allows. I make sure my Service, Controllers, DAO/Repositories never hold state. I never make my domain objects as beans because they hold state and trying to declare 1 million beans to instantiate my entire customer table database for the Customer domain object, just doesn't make sense.

So you need to look at your definition of concurrency issue, and see if it is correct?

Mark
 
Rajesh Santhanakrishnan
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks for the reply.

In our web application we use simpleFormController.
We used to set the views using formView() & successView().
At the end of the controller methods we used to pass the successview to ModelAndView class.



Scope of the controller is singleton.
When we access the controller concurrently, successView & formView gets swapped, resulting in unexpected page.
Since major portion of the application is already developed , avoiding the use of successview & formview is a big change.

To overcome this issue we changed the scope of the controller to 'Request', so that for each request will have a new instance of controller & in turn we have seperate successview & formview.

Please let us know if there is any potential hazards because of this fix.
Or is there any better soultion for this.

Thanks

 
Mark Spritzler
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please post your Controller code, I am sure it is a coding issue. Why is your controller holding any state anyway, especially if it could change between users. I would refactor that in a cleaner approach.

I am sure there is a mistake in the coding that needs to be fixed, and by changing the Scope of a controller you are instead curing the cold by adding another symptom that masks the first symptom, so you still have a cold in your code, now it is a bigger cold.

Mark
 
Mark Spritzler
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am more leaning that you are using the successView and formView in the wrong ways. formView is for the GET, and successView is for the POST, they should never be switched, and they should never change based on user.

Mark
 
Rajesh Santhanakrishnan
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Due to some restrictions i am unable to post the code.

In our application we use same controller for different pages instead of single controller for single page.
So we override formView & successView based on the different methods called.

Sample code



setView() method is called to override the successView() of the controller.

We have seperated the view setting logic to setView() method.

So when multiple users trying to access the controller at the same time the successView is getting changed.
I guess in my previous post that i ve mentioned wrong that successView & formView are getting overlapped.
Its actually the multiple successView's getting overlapped
This is what the concurrency issue we are facing.

Thanks
 
Mark Spritzler
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, so then you are misusing the class/interface. The interface is designed to be used for one page/url only. This is also a big reason why in current versions of Spring and Spring MVC the best approach is using POJOs and Annotations in your Controllers. When you try to do things opposite of the contract of the interface, then all bets are off.

You can implement things a bit differently to work in your scenario. Instead you can overwrite get/setFormView and get/setSuccessView, create a Map in your Controller to hold the formView and successView for each page. using the URL as the key and a special Domain object that holds two properties for formView and successView. then get the values from the map instead of the single attribute in the class.






Something along those lines. Now I just quickly wrote that code here, so I have no idea if it will actually work, but the logic is sound.

Mark
 
Rajesh Santhanakrishnan
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply.
That sounds logical.
But still even for same method we may have different views based on a command variable which differntiates which page it has to navigate.

For example
Lets say page1.jsp, page2.jsp,page3.jsp.User can navigate to page3 from either page1 or page2.
On navigating back from page3, user should go back to the page from where he navigated from.
Consider user1 navigates from page1 to page3 and user2 navigates from page2 to page3.When accesed concurrently , on navigating back from page3 user1 gets page1 as successView but user2 gets page1 as successview instead of page2
The command variable will be set from where the user had naigated from, which also will be a condition along with method name to set the succesview

Thanks
 
Mark Spritzler
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the sounds of your description there, that is what Spring WebFlow is for.

For the getCommandName, you can overwrite any method to handle what you need. You just can't use the basic form of that class, because that classes purpose is not for what you are trying to use it as.

It is like trying to solve your problem and using a JDBC Connection. They are for different purposes, and while you might find a way to subclass JDBC Connection to handle your situation, it wouldn't be a good idea because a JDBC Connection is for connecting to JDBC, not for a simple Web Form.

Does that make sense. You can specialize the class, but you can't make it do something it wasn't intended to be used for.

Mark
 
It's a tiny ad only because the water is so cold.
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic