wood burning stoves 2.0*
The moose likes Struts and the fly likes General Web app question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Struts
Bookmark "General Web app question" Watch "General Web app question" New topic
Author

General Web app question

Justin Allen
Greenhorn

Joined: Feb 02, 2011
Posts: 18

So I've just started a new job and we've got a traditional web app setup(Tomcat, Struts1, Sybase DB) and I have a question about design and synchronization. I've worked on a previous web app and all of our beans were never synchronized. We just created a new set of object's for every user and then served that information up. Now on this application the have decided to synchronize some of their operations on information. Is there really a need to do that in a web app? If you give every user a new set of object's there should be no problems with one user modifying another's information? They should all write to the DB and if one user is modifying the same information as another, the DB will just over-write the older information?

If we didn't share any of the objects between requests(meaning we create a distinct set of objects for each request) there should be no need for synchronization correct?

thanks!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61309
    
  66

That is correct. (Assuming that the objects aren't stored in the session or app contexts, which are shared.)


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Justin Allen
Greenhorn

Joined: Feb 02, 2011
Posts: 18

Thanks for the information Bear, that is very helpful. One followup question if we do add things to the user session would be it be best to synchronize mutators on those objects? Or should I just do some more investigation about how sessions are shared in tomcat?

thanks!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61309
    
  66

The contention for session objects occurs due to frames, frames, additional windows, or Ajax from the same user, as the session cookie is shared amongst them. You won't need to worry about contention from other users on other systems.

I try to minimize, or completely eliminate, storing any read/write data in the session.
Justin Allen
Greenhorn

Joined: Feb 02, 2011
Posts: 18

Excellent, thank you for all the good information. Unfortunately my system uses a lot of ajax and has been deployed in production for a while. I've been tasked with improving the performance, so I will take what you've told me and try to refactor the code I have to use the session less and less where I can. Thank you!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61309
    
  66

Before you move to sharing any instances using synchronization, make sure that it will actually increase performance. In most cases, it actually hinders performance.
Justin Allen
Greenhorn

Joined: Feb 02, 2011
Posts: 18

I will. I think my general approach for now, will be trying to get the synchronization out of the system slowly. We have lots of instance's of Vector's and Hashtable's floating around that I think can slowly be converted to List's and Map's of various kinds. I need to do more investigation into my system to determine what really needs to be in the session and what doesn't and also what really needs to be synchronized, because it is my feeling right now that alot of the stuff that is synchronized has been done so for no good reason.
Mohana Rao Sv
Ranch Hand

Joined: Aug 01, 2007
Posts: 485

@TS Yeah those are two types of design approaches and that is one of the major difference between struts 1 & struts 2. In struts 2.0 developer need not to worry about synchronization because new instance will be created for each and every request.


ocjp 6 — Feeding a person with food is a great thing in this world. Feeding the same person by transferring the knowledge is far more better thing. The reason is the amount of satisfaction which we get through food is of only one minute or two. But the satisfaction which we can get through the knowledge is of life long.
 
GeeCON Prague 2014
 
subject: General Web app question