aspose file tools*
The moose likes Tomcat and the fly likes Tomcat: dual requests to same action result in missing session data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Tomcat: dual requests to same action result in missing session data" Watch "Tomcat: dual requests to same action result in missing session data" New topic
Author

Tomcat: dual requests to same action result in missing session data

Eric Springer
Greenhorn

Joined: Apr 25, 2008
Posts: 4
Hello everyone,
I'm experiencing an odd problem and having a rather difficult time finding answers online -- has anyone else experienced something like this?

I'm running a webapp using Java in Tomcat 5.5. During some simultaneous testing the other day, my coworker and I found that if we both tried to retrieve the same data set at the same moment, one of us would see data returned on the JSP and one would not.

It seemed to only occur when retrieving large amounts of data from the database, so I investigated this further on my local machine, logging into the app with two users at once, one in firefox and one in IE, using eclipse debugger to see if this was a database transaction problem or not.

I cut out the database portion entirely, instead creating a large ArrayList of objects within Java. I found that the problem didn't occur until I created a large list with 50,000 objects in it. Code is as follows:

int i = 0;
int x = 50000;

while(i < x) {
BMPCatValue bmpCatValue = new BMPCatValue();
bmpCatList1.add(bmpCatValue);
i++;
}

StringBuffer attrName = new StringBuffer();
attrName.append(SessionKeys.EC_BMP_CATEGORY_LIST_BY_CLIENT);
attrName.append(sessionId);
String attr = attrName.toString();
//setSessionAttribute(SessionKeys.EC_BMP_CATEGORY_LIST_BY_CLIENT, bmpCatList1);
setSessionAttribute(attr, bmpCatList1);

List bmpCatList2 = (List)request.getSession().getAttribute(attr);
LOG.debug("ERS: got the list." + bmpCatList2);
Eric Springer
Greenhorn

Joined: Apr 25, 2008
Posts: 4
Whoops, submitted before I was finished.

Anyway, if I watch both requests from Firefox and IE come in via Eclipse debugger, I can see that each user gets their bmpCatList1 populated with all 50k objects. Then the call to place the list in the session occurs.

At this point user2's list (the user who clicked second) is put into the session successfully. Pulling it back out in bmpCatList2 shows results. User1's instance however, fails to place the data in the session. The line is executed and nothing happens. Then, when the same list is pulled back out below, bmpCatList2 shows "null."

I am appending the session_ids to the attribute name to ensure they weren't "overwriting" each other in the session (even though they are different requests) and saw that the session ids were in fact different.

So why does User1 get their results "cut off" so to speak, with User1 getting their data and having to placed successfully in the session?

Any ideas appreciated. Thanks.
Stevi Deter
Ranch Hand

Joined: Mar 22, 2008
Posts: 265

Eric,

Where and how to you actually declare bmpCatList1?


There will always be people who are ahead of the curve, and people who are behind the curve. But knowledge moves the curve. --Bill James
Eric Springer
Greenhorn

Joined: Apr 25, 2008
Posts: 4
Within the same action class, just above the loop -- omitted the line in copy/paste.

ArrayList bmpCatList1 = new ArrayList(); // implements java.util.ArrayList

My request implements javax.servlet.http.HttpServletRequest and my setSessionAttribute() method is below.

protected void setSessionAttribute(String name, Object obj) {
request.getSession().setAttribute(name, obj);
}
Stevi Deter
Ranch Hand

Joined: Mar 22, 2008
Posts: 265

Eric,
Are you seeing any errors logged by tomcat in the logs dir?

If it only happens for large result sets, it might be a memory problem of some sort; you may need to increase Tomcat's heap size.

That's my best guess at this point based on your description and my experience with Tomcat.

Perhaps some other rancher has some additional tips for troubleshooting these sorts of problems.
Eric Springer
Greenhorn

Joined: Apr 25, 2008
Posts: 4
Thanks for the suggestion Stevi, that also occurred to me. I increased the Tomcat memory pool from 768 to 1024 with no improvement.

I also added 'synchronized' to my action method, but that didn't solve the issue either. Very very confusing.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12823
    
    5
I would suspect that session management is trying to serialize a session due to low memory and that serialization is failing. This should result in error messages somewhere.

Bill
 
 
subject: Tomcat: dual requests to same action result in missing session data