Java EE – How to Perform Session Swap in J2EE

javajava-eesession

Application server – JBoss AS 7.1.1
JDK6
J2EE 1.3

My web application is more than 10 years old and facing this session swap problem in my portal. Noticed
that swap happens mostly when many concurrent users accessing the portal and underlying windows server is busy
(more than 90% CPU usage)

To analyse this issue, I logged customer data (customer id, ip address, jsession id) to a table and found
that customer having unique jsession id initially has his data and all of a sudden for the same jsession id and
ip address receiving different customer data.

customer1  123.123.12.123   jsessionid123    11:10:02
customer2  123.123.12.123   jsessionid123    11:10:04

ip address (123.123.12.123) having jsession id (jsessionid123) somehow gets customer2 data

Any order placed by customer1 in ip – 123.123.12.123 gets created for customer2, I confirmed this by
calling customer2 and they confirmed that they didn't place the order. customer1 won't realise he placed
order for customer2 – all the data gets changed, like basket items, customer object, products etc.

Now I need to find a fix for this, but first I need to know which part of my code is creating this problem.

Do I have to use a stress test software? or any better mechanism to find out the problematic code?

Best Answer

Look whether you are storing data in singletons (eg servlet) or in pooled objects. To be clear, variables inside function are ok, only something in servlet itself is problem. In comment you say you choose action, if you choose existing instance, then you should not store session wide data in it.

Once I seen (ehm, caused) similar problem caused by incorrectly using phase listeners (in JSF) where we created listener for each request (which led to similar sindroms + after while it was extremely slow (executing listeners extremely many times). I quess that this is not your problem.

Related Topic