This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
Problem in Struts 2 when run multiple threads concurrently
Vivekanandan Anandan
Greenhorn
Joined: Mar 10, 2010
Posts: 3
posted
0
How to design and code my application in Java to allow multiple client threads to run concurrently throughout the application without interfering with one another?
Now, i hit problem when i try to send 2 threads concurrently, and when second thread is coming in, it overwrites the variable instance value which belong to first thread. So, the first thread will get a wrong value from the variable instance to proceed.
I'm not sure what you're asking. Struts 2 creates an action-per-request--what instance values do you believe are being modified by two separate threads? What kind of threads are modifying them?
Mark E Hansen
Ranch Hand
Joined: Apr 01, 2009
Posts: 639
posted
0
Keep in mind that if you're testing this by running multiple browsers on the same client computer, depending on the browser it can look to the server like requests from the same client, and therefore belonging to the same session.
Vivekanandan Anandan
Greenhorn
Joined: Mar 10, 2010
Posts: 3
posted
0
I am using a Action called SamleAction.java
Declared a static variable count and incrementing it when ever the method is called.
in logging the references of request and response you can see the following
Here when the method is called consecutively you can see the "Start" line two times with same request and response objects.
the response for the line 5 is not received
Lorand Komaromi
Ranch Hand
Joined: Oct 08, 2009
Posts: 276
posted
0
Vivekanandan Anandan wrote:Declared a static variable count and incrementing it when ever the method is called.
You either synchronize yourself or use an AtomicInteger and its incrementAndGet() method.
OCJP 6 (93%)
Vivekanandan Anandan
Greenhorn
Joined: Mar 10, 2010
Posts: 3
posted
0
Thanks for your reply Lorand.
But the thing here is for line 4 and 5 the references for request and response were same.
That is, when thread for line 5 is coming in, it overwrites the variable instance value which belong to thread line 4 .
as because the line 4 will get a wrong value from response and the response for line 5 is not at all received.
(Am sending xml as response as am using flex for front end)
Lorand Komaromi
Ranch Hand
Joined: Oct 08, 2009
Posts: 276
posted
0
The problem is the static variable, which is shared across action class instances (==> shared across threads), this is a classic multithreading issue...
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: Problem in Struts 2 when run multiple threads concurrently