• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem in Struts 2 when run multiple threads concurrently

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 650
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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


Start--01--StrutsRequestWrapper@867ca8-->ResponseFacade@169b9e3
End--01--StrutsRequestWrapper@867ca8-->ResponseFacade@169b9e3
Start--02--StrutsRequestWrapper@872ebe-->ResponseFacade@169b9e3
End--02--StrutsRequestWrapper@872ebe-->ResponseFacade@169b9e3
Start--03--StrutsRequestWrapper@1b593d2-->ResponseFacade@169b9e3
End--03--StrutsRequestWrapper@1b593d2-->ResponseFacade@169b9e3
Start--04--StrutsRequestWrapper@f663e4-->ResponseFacade@169b9e3
Start--04--StrutsRequestWrapper@f663e4-->ResponseFacade@169b9e3
End--04--StrutsRequestWrapper@f663e4-->ResponseFacade@169b9e3
End--05--StrutsRequestWrapper@f663e4-->ResponseFacade@169b9e3

Start--06--StrutsRequestWrapper@152db16-->ResponseFacade@169b9e3
End--06--StrutsRequestWrapper@152db16-->ResponseFacade@169b9e3

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
 
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Vivekanandan Anandan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 276
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem is the static variable, which is shared across action class instances (==> shared across threads), this is a classic multithreading issue...
 
Don't mess with me you fool! I'm cooking with gas! Here, read this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic