File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes synchronize in struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "synchronize in struts" Watch "synchronize in struts" New topic

synchronize in struts

emmel torres

Joined: Feb 06, 2009
Posts: 1

I have a web application and will have users connected to it simmultaneous.

The problem is the next:

With Accept button go to Configuration Action class, and it makes a session.setattribute("configuration", config_object) for save some object into session, after it redirect to Generation Action class.

Generation Action class make a session.getattribute("configuration") for get the object saved in Configuration Action class, after it
Generation Action class make a session.setattribute("generation", generation_object), and session.setattribute("configuration", config_object_modified) after it redirect to the jsp.

In the jsp obtain the attributes with:
<jsp:useBean id="generation" scope="session" class="package.generationActionForm"></jsp:useBean>
<jsp:useBean id="configuration" scope="session" class="package.configurationActionForm"></jsp:useBean>

The problem is when two user acceded to click button I guess that the setattribute are saving like to application scope (getServlet().setattribute..) because both users the application display the same information and at the began the configuration was different. If the users acceded in different second the application run correctly.

If I synchronize the execute methods of Generation Action class and Configuration Action class the application runs correctly; but I dont want it, because if the user1 acceded to the database and his/her SQL Query runs slowly, the second user will be waiting until user1 finish.

Thanks! I hope I can help
David Newton

Joined: Sep 29, 2008
Posts: 12617

Each user has a separate session.

If you're testing locally and attempting to simulate two users on a single machine then you might have a problem--different browsers handle the opening of new windows differently; some create a new session with the server, some don't. The best solution is to use two different browsers for two different users.

If two users on separate *machines* are getting the same session then something is very wrong with your server.
I agree. Here's the link:
subject: synchronize in struts
It's not a secret anymore!